Skip to content

h props to behave more like React #183

Open
@onlyfortesting

Description

@onlyfortesting

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions