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

h props to behave more like React #183

Open
onlyfortesting opened this issue Sep 15, 2021 · 1 comment
Open

h props to behave more like React #183

onlyfortesting opened this issue Sep 15, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@onlyfortesting
Copy link

Hey @luwes. I have been building something with this library for 2 weeks now and it's been great so far.

But, I notice a bit of unusual pattern when building components using JSX.
Since JSX transpiler always pass null if props param is empty like:

// JSX
<Component>Hello</Component>

// Transpiled
h(Component, null, "Hello")

In Sinuous, you can't destructure props like this:

const Component = ({ name, intent, as, icon, onDrag, onDrop }) => {
  // Do something with props

  return (
    <div>
      ...
    </div>
  )
}

It throws error simply because props is null.

So, you need to this instead:

const Component = (props) => {
  let { name, intent, as, icon, onDrag, onDrop } = props || {}
  // Do something with props

  return (
    <div>
      ...
    </div>
  )
}

In React you can do that, because React internally checks for null props and pass {} instead.
I plan to build a lot of components and this pattern is slightly annoying. Do you mind if I submit a PR?

Thank you

@luwes luwes added the enhancement New feature or request label Jan 31, 2022
@luwes
Copy link
Owner

luwes commented Jan 31, 2022

@onlyfortesting sorry for the late reply here, yes please submit a PR. Very welcome. Thanks!

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

No branches or pull requests

2 participants