admin管理员组文章数量:1395889
I was working on the code of a practice for React, but I stopped because I have to make a navigation bar be shared among other pages
I found the next solution and it works but I don't know how exactly works; this is for a course project.
function Layout(props) {
return(
<React.Fragment>
<Navbar />
{props.children}
</React.Fragment>
);
}
I can't really know what really {props.children}
does and how if Layout ponent start holding other ponents the Navbar ponent still appears
<Layout>
<Switch>
<Route exact path="/badges" ponent={Badges}/>
<Route exact path="/badges/new" ponent={BadgeNew} />
</Switch>
</Layout>
What happens behind the scenes?
I was working on the code of a practice for React, but I stopped because I have to make a navigation bar be shared among other pages
I found the next solution and it works but I don't know how exactly works; this is for a course project.
function Layout(props) {
return(
<React.Fragment>
<Navbar />
{props.children}
</React.Fragment>
);
}
I can't really know what really {props.children}
does and how if Layout ponent start holding other ponents the Navbar ponent still appears
<Layout>
<Switch>
<Route exact path="/badges" ponent={Badges}/>
<Route exact path="/badges/new" ponent={BadgeNew} />
</Switch>
</Layout>
What happens behind the scenes?
Share Improve this question edited Jul 24, 2019 at 7:58 wuarmin 4,0254 gold badges20 silver badges37 bronze badges asked Jul 24, 2019 at 4:25 Pablo VerduzcoPablo Verduzco 1212 silver badges11 bronze badges2 Answers
Reset to default 7props.children
means that React will render whatever u put between Layout
ponent.
For ex, if u put a div block between Layout ponents, props.children
will be that div.
Every JSX code that you put inside the Layout
-tag, will be placed in children
property of props
-object of the Layout Component.
<Layout>
<div>this is a child</div>
<AnotherReactComponentAsLayoutChild/>
</Layout>
本文标签: javascriptHow quotpropschildrenquot works on a React componentStack Overflow
版权声明:本文标题:javascript - How "props.children" works on a React component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744088885a2589052.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论