Saying inline functions in render is bad is like correcting somebody who said "who" to say "whom" when "who" was actually correct.
And if there's only one child this.props.children is the child? Or this.props.children[0]?
-
-
Right, a single child would be available as this.props.children. You can use React.Children.only to ensure you only have a single child too
-
Wouldn't it be more convenient to have direct syntax for this in JSX?
-
I believe that is some people’s objection. Children as a function is not a valid type for children according to docs.
-
It's fine. People are just prematurely optimizing and its starting to spread. That's all.
-
Also, the docs explicitly state functions as children is a valid, seehttps://facebook.github.io/react/docs/jsx-in-depth.html#functions-as-children …
-
Glad to see it officially supported. My only objection was what if it disappeared. Didn’t want to rely on an unsupported API/feature
-
children has always been "just a prop". What you put there doesn't matter. It's special because of its position in JSX (and createElement)
-
I mean this usage is visually pretty noisy just to add a parameter to a callback. But whatever floats ppl's boats.
- 4 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.