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

Array of JSX is not allowed #74

Closed
avi892nash opened this issue Jun 13, 2024 · 1 comment
Closed

Array of JSX is not allowed #74

avi892nash opened this issue Jun 13, 2024 · 1 comment

Comments

@avi892nash
Copy link

avi892nash commented Jun 13, 2024

The type of component function does not allow to create react component with Array JSX return.

This should get compile, because react library allowes this syntax.

mkCounter :: Component Int
mkCounter = do
  component "Counter" \initialValue -> React.do
    counter /\ setCounter <- useState initialValue

    pure
      $ [ R.button
          { onClick: handler_ do
              setCounter (_ + 1)
          , children:
              [ R.text $ "Increment: " <> show counter ]
          }
          ]
@pete-murphy
Copy link
Member

Yeah Component is just a type alias

type Component props = Effect (props -> JSX)

so if you have an Array JSX that you want to return, the recommendation is to use fragment :: Array JSX -> JSX https://pursuit.purescript.org/packages/purescript-react-basic/17.0.0/docs/React.Basic#v:fragment

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