Preact: why preact props has default children?

Created on 19 Jul 2017  路  12Comments  路  Source: preactjs/preact

i didn't has children props,
2017-07-19 5 08 43

but i console this datepicker proptypes, why has a children is undefined?

2017-07-19 5 07 29

in X question

Most helpful comment

Preact normalizes children in h() - it will always set props.children to an Array. preact-compat undoes this for React-style components, which is why you're seeing the undefined. Deleting the property would mutate the shape of props and hurt performance, so it is simply set to undefined.

All 12 comments

Preact normalizes children in h() - it will always set props.children to an Array. preact-compat undoes this for React-style components, which is why you're seeing the undefined. Deleting the property would mutate the shape of props and hurt performance, so it is simply set to undefined.

@developit hmm, could we disable default children array? with an attribute like noChilds ?

Just faced that issue with paypal integration, they are validating the props, and they only allow some limited props.. (children is not included)

Really, don't want to install preact-compat just for this.

@developit I'm a colleague of @a993630 , I understand your pursuit of performance, but this hurt the compatibility of Preact. Unlike @webdeb , my project has included preact-compat, but still got some warnings with prop-types.
Not all the third-party packages is well-maintained / quickly-responded, nor every project would like to change some code to fit Preact, this means hurting the eco-system of Preact.
Please consider.

@developit this will prevent adding undefined children to props https://github.com/developit/preact/pull/774

I'm happy with the proposed solution in #774. The issue I had was that, when not using preact-compat, props.children is always an Array in Preact. This is done intentionally, to avoid requiring the entire React.Children API, which exists only because children is an unknown object in React.

We are also experiencing an issue with a 3rd party React library that is not compatible with undefined children when using preact-compat.

@webdeb Any progress on #774 or #822?

Hey @Zeroster, because #822 adds more complexity, I decided to re-open #774 again. If @developit is still OK with it, it would make me proud if #774 could be merged any time soon. Btw, this would also allow me to use the official Preact package instead of mine custom fork in one of my projects ;)

This is something that my team needs. Are there any updates on the progress of this issue? Information is appreciated. Thanks!

@theramparts #774 should be ok to merge, IMHO

@developit Can we get this merged in? My team would be very appreciative! Thanks.

We just merged #1302 which doesn't automatically add props.children anymore :+1:

Was this page helpful?
0 / 5 - 0 ratings