You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems to me like most components don't need this.props.children, so to me that makes it extra important to document children in the propTypes.
I think the option idea is fine. I'm interested in hearing why anyone would want to run this against all other prop types, but never against children. It seems not well thought out to me, but I kind of hope I'm just missing something.
arnemahl, couto, aryasabeti, Mastergalen, jeffpowrs and 39 moreStorky, Jfree64 and liuliangsir
richarddewit, ben-eb, francescabassi, osartun, ream88 and 275 moreArtexoid, farminf, gyurobenjamin, guilhermealles, dvzore and 6 moreOscuro1111 and liuliangsirnikolenkoanton92, liegeandlief-hx, tituswoo, mlwigdahl, zaunermax and 49 more
React.PropTypes.any is also an option. If I really had a component that could support 0, 1, or more children I'd probably just stick with .any to document that children is used.
Demven, eruixma, ksarna, balaclark, maryam-saeidi and 7 more
Hmmm, my component is a wrapper, which could stand on its own, so I didn't set a default prop value. Bad practice? I guess if I had to set one then it should be null
Activity
yannickcr commentedon Mar 2, 2015
Right, we should add an exception for
this.props.children
AsaAyers commentedon Mar 24, 2015
Why should children be an exception? I think you should document when a component does accept or require children.
yannickcr commentedon Mar 24, 2015
You're right, but I rarely seen some propTypes for
this.props.children
so it dot not seems to be a common practice to me.Maybe we can introduce an option to
prop-types
to re-include children in the props list to check?AsaAyers commentedon Mar 24, 2015
It seems to me like most components don't need
this.props.children
, so to me that makes it extra important to documentchildren
in thepropTypes
.I think the option idea is fine. I'm interested in hearing why anyone would want to run this against all other prop types, but never against children. It seems not well thought out to me, but I kind of hope I'm just missing something.
sebastienbarre commentedon Apr 7, 2015
All good points. [UPDATED]
I think @AsaAyers is onto something, considering the Single Child section in the React doc:
In other cases when
this.props.children
might be used (or not), this below could probably do the trick:remitbri commentedon Apr 7, 2015
I ended up with
React.PropTypes.node
to solve my issues…AsaAyers commentedon Apr 7, 2015
It looks like I have a combination of
element
,node
, a fewstring
s, and anarrayOf(...shape(...))
.sebastienbarre commentedon Apr 7, 2015
@remitbri thanks, I updated my comment above accordingly. What's your default prop value?
null
?AsaAyers commentedon Apr 7, 2015
React.PropTypes.any
is also an option. If I really had a component that could support 0, 1, or more children I'd probably just stick with.any
to document thatchildren
is used.remitbri commentedon Apr 7, 2015
Hmmm, my component is a wrapper, which could stand on its own, so I didn't set a default prop value. Bad practice? I guess if I had to set one then it should be
null
yannickcr commentedon Apr 7, 2015
Since 2.0.0
children
is no longer ignored for props validation.If you still want to ignore it you can use the
ignore
option.6 remaining items
resistdesign commentedon Nov 29, 2015
I know this is closed, but wouldn't
children
be inherited fromComponent
? Or is OOP not a thing anymore?AsaAyers commentedon Nov 29, 2015
Not all Components have children. In a couple of my projects I have an
<Avatar user={userObject} />
joaomilho commentedon Jan 25, 2016
@resistdesign actually yeah, OOP is not the main thing anymore, at least in React's world.
lencioni commentedon Sep 16, 2016
Why do you need
oneOfType
here? Thenode
propType is defined as "Anything that can be rendered: numbers, strings, elements or an array (or fragment) containing these types." https://facebook.github.io/react/docs/reusable-components.htmlYou should use
children: PropTypes.node
.jdanilov commentedon Feb 18, 2018
Justin case you're wondering how to do that in Flow, use React.Node as described here:
https://flow.org/en/docs/react/types/#toc-react-node
Denly commentedon Mar 15, 2018
PropTypes.node can be an array, so no need the React.PropTypes.arrayOf(React.PropTypes.node) @sebastienbarre