Component that accepts children
See original GitHub issueI am trying to write a wrapper component that puts a panel around whatever children are passed.
In React, I can usually do something like
var Frame = React.createComponent({
render: function() {
return <div>{ props.children }</div>
}
});
and then use it like
<Frame>some content</Frame>
I assume that in Scalajs-React I can explicitly pass some props that contains Seq[ReactComponents]
as a property, but I was wondering if the case of passing children, which has special treatment in React, also gets a special treatment here
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Composition vs Inheritance - React
React has a powerful composition model, and we recommend using composition instead of inheritance to reuse code between components.
Read more >A quick intro to React's props.children | by Jason Arnold
The React docs say that you can use props.children on components that represent 'generic boxes' and that 'don't know their children ahead of ......
Read more >React Children And Iteration Methods - Smashing Magazine
In this article, we'll discuss and learn about the use case of iterating over React `children` and the ways to do it. In...
Read more >Using Children in React - We Learn Code
You can use props.children in React in order to access and utilize what you put inside the open and closing tags when you...
Read more >Component Children | Build with React JS
Children allow you to pass components as data to other components, just like any other prop you use. The special thing about 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
Thank you both, it works perfectly!
For future readers: what works is passing the children after the props when instantiating the component, and using a form of
render
with two parameters, like this:Just for the record: to make a childless component accept children,
.renderBackend[Backend]
with.renderBackendWithChildren[Backend]
def apply(p: Props) = component(p)
withdef apply(p: Props)(child: ChildArg*) = component(p)(child:_*)
def render(p: Props, s: State)
withdef render(p: Props, children: PropsChildren, s: State)
render
method (for example usingvdomNodeFromPropsChildren(children)
)