我可以在 React 的 Component 中编写 Component 吗? [英] Can I write Component inside Component in React?
本文介绍了我可以在 React 的 Component 中编写 Component 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到过很多关于如何进行 Component
嵌套的资料.但是,每当我尝试在另一个 Component
中创建一个 Component
时,我的代码都会失败.
class parent extends React.Component{class child 扩展 React.Component{使成为(){返回<div><h1>Hiiii</h1></div>;}}使成为(){返回<div><DEF/></div>;}}
解决方案
组件嵌套意味着在其他组件内部渲染 React 组件.喜欢
<div><子组件/>...
</父组件>
I have come across many sources which talk about how to do Component
nesting. However, whenever I try to create a Component
inside another Component
my code fails.
class parent extends React.Component{
class child extends React.Component{
render(){
return <div><h1>Hiiii</h1></div>;
}
}
render(){
return <div><DEF /></div>;
}
}
解决方案
Comoponent nesting means rendering react components inside other components. Like
<ParentComponent property={value}>
<div>
<ChildComponent />
...
</div>
</ParentComponent>
这篇关于我可以在 React 的 Component 中编写 Component 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文