我想实现一个接受嵌套组件的自定义组件。可以这样用的东西。
<MyCustomComponent>
<AnyNestedComponent/>
</MyCustomComponent>我对此进行了搜索,但只发现了this.props的使用,这不是我所期望的。
如何在React本机版本MyCustomComponent中实现0.68
注: MyCustomComponent将由View(s)组成。
发布于 2022-08-22 08:10:11
它在RN中相当简单,
您的customComponent应该是=
const CumstomComp = ({props = {}, children = null}) => {
return(
<View style={{backgroundColor:"red"}} >
{children}
</View>
)
}然后你就这样用它
App.js或其他文件
const App = () => {
return(
<View>
<CustomComp>
<Flatlist />
<View />
</CustomComp>
</View>
)
}希望能帮上忙。有疑问就放心吧
https://stackoverflow.com/questions/73441942
复制相似问题