Preact Children Props Array is always empty
See original GitHub issuePreact doesn’t count children returned from a component’s render function as children for example
render(props, state) { return(<div><ComponentOne/><ComponentTwo/></div>); }
will always have props.children = []
This is inconsistent behavior from React where the children props absolutely are counted. Also before you close this issue as a non-bug, please give guidance on how to properly get props.children to show the correct information
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Preact Children Props Array is always empty #1174 - GitHub
This is inconsistent behavior from React where the children props absolutely are counted. Also before you close this issue as a non-bug, please ......
Read more >React: props is always an empty array when passed to child
When I log the safedEvents array in the parent class it is not empty. The safedEvents array is initialized via useState(). Here is...
Read more >Jason Miller on Twitter: " POLL: Preact currently represents "no ...
POLL: Preact currently represents "no children" as an empty props.children Array. Do you think this should be changed (back) to null?
Read more >API Reference | Preact
When there are multiple children, props. children is always an Array. The toChildArray helper provides a way to consistently handle all cases.
Read more >Array Passed in Props Showing Up as Empty - Stack Overflow
The actually reason you face this strange behavior is because your code App is wrapped with StrictMode that renders your component twice.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
props.children
is always an Array containing the JSX elements and text values passed as children to a given component. It’s normalized:h('div', { children: 'one' }).children === ['one']
We may consider moving towards React’s behavior (no normalization whatsoever) in future versions, but it would be a fairly major breaking change and would require shipping the entire
Children
interface (likely 500b on its own).Note: I found both your examples confusing - you’re returning children from a render function, not passing children to a render function:
Please don’t open duplicates: https://github.com/developit/preact/issues/1173
If you create a running code sample to demonstrate the differences between React and Preact it might be easier to understand your question.