Reputation: 228
Let's say I have too many wrapper components A, B, C .....
Sometimes I want to render
<A>
<Text>{this.state.myText}</Text>
</A>
And some other times I want to render
<B>
<Text>{this.state.myText}</Text>
</B>
....
....
....
How to achieve something like this?
{this.bringTheRightComponentTag(this.state.wrapperComponent)}
<Text>{this.state.myText}</Text>
{this.bringTheRightComponentClosingTag(this.state.wrapperComponent)}
This is a minimized example. I just need to learn the logic.
Upvotes: 0
Views: 297
Reputation: 1850
React actually allows you to assign the component to a variable during runtime( Docs here). So you can do something like,
const SelectedComponent = true ? A : B
return (
<SelectedComponent>
{this.state.myText}
</SelectedComponent>
)
Upvotes: 2