Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous component #153

Open
yhatt opened this issue Apr 28, 2020 · 2 comments
Open

Asynchronous component #153

yhatt opened this issue Apr 28, 2020 · 2 comments

Comments

@yhatt
Copy link
Owner

yhatt commented Apr 28, 2020

I discovered jsx-slack v2 can use asynchronous component as following:

const AsyncComponent = async ({ userId }) => {
  // Fetch some data
  const name = await getUserName({ id: userId })

  return <Section>Hello, {name}!</Section>
}

;(async () => {
  console.log(
    <Blocks>
      <Context>Asynchronous component example</Context>
      <Divider />
      {await <AsyncComponent userId={123} />}
    </Blocks>
  )
})()

TypeScript requires to cast the component into any type.

This usage was found out by chance and it's out of our specification, but may have a worth to write down to the documentation as one of the useful way to use async functions.

@varadiistvan
Copy link

Hey! We're using jsx-slack in our project, and was wondering if this was possible on current version? The workaround we found for now is calling components as functions, but that's kind of ugly to do

@yhatt
Copy link
Owner Author

yhatt commented May 23, 2023

Yes, this code is still working in JavaScript with the current version of jsx-slack (v6), without no changes. 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants