Reputation: 1015
I've a component like
<A componentAsProps={<Text>Some Text</Text>} />
How to render componentAsProps in render method
Upvotes: 1
Views: 65
Reputation: 1015
I found the answer all I need to do it
{this.props.componentAsProps}
in render method of child component
Upvotes: 0
Reputation: 1280
You can do something this :
renderChildCompo = () => <Text>Some text</Text>;
render() {
return (
<A componentAsProps={this.renderChildCompo} />
);
}
// ...
And in your ./A/index.js file
render() {
return (
{this.props.componentAsProps()}
);
}
Upvotes: 4
Reputation: 527
You can just pass a component as children:
Parent component:
<ChildComponent>
<Text>Some Text</Text>
</ChildComponent>
Child component:
class ChildComponent extends Component {
render() {
return (
<View>
{this.props.children}
</View>
);
}
}
OR you can pass a value as prop and use it like this:
Parent component:
<ChildComponent text="Some Text" />
Child component:
<Text>{this.props.text}</Text>
Upvotes: 1