PropsChildren's type isn't exactly Array
See original GitHub issueI have a component that can pass children nodes which can be empty:
object Hello {
private val ComponentName = this.getClass.getSimpleName
private case class Props(message: String)
private case class Backend(scope: BackendScope[Props, _]) {
def render(P: Props, C: PropsChildren): vdom.ReactTagOf[Div] = {
println(C)
// If C is empty then render an empty div
if (C.isEmpty) {
<.div()
} else {
<.div(^.cls := "message",
C,
P.message
)
}
}
}
private val component = ReactComponentB[Props](ComponentName)
.stateless
.renderBackend[Backend]
.build
def apply(message: String)(children: ReactNode*): ReactComponentU[_, _, _, TopNode] = {
component(Props(message), children: _*)
}
}
My attempt to use is
Hello("message here")() // Is this correct way to pass an empty child?
Hello("message here")(<.div("Children"))
It compiles successfully, but when loading the page on browser, I got the exception for the 1st usage (Hello("message here")()
):
I added println(C)
inside the Backend.render()
method, and I got undefined
when calling (Hello("message here")()
).
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Why is `this.props.children` not an array when there's just one ...
It makes it more difficult to work with when you have to take account that it may sometimes be a single child and...
Read more >Questions regarding "props.children" · Issue #12913 - GitHub
Why exactly isn't props.children in case there are some children (one ore more) just always an array (as it is done in "Preact"...
Read more >Find & Filter React Children By Type - Michael Paravano
This article will discuss the how-it-works for finding and filtering React children by type as it pertains to custom component children.
Read more >A deep dive into children in React - Max Stoibers Blog
What they are essentially telling us is that props.children can be any type, such as an array, a function, an object, etc.
Read more >Typechecking With PropTypes - React
import PropTypes from 'prop-types'; class Greeting extends React. ... must be exactly one element or it will warn. const children = this.props.children; ...
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 Free
Top 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
This will be fixed as part of #259.
Fixed on
topic/neo
branch.