I went to render a component using Ternary expression.
Currently I a doing something like this
<View style={container}>
{ this.state.loaded ?
(<VictoryChart
theme={VictoryTheme.material}
>
<VictoryArea
style={{ data: { fill: "#c43a31" } }}
data={this.coinHistoryData}
x="cHT"
y="cHTVU"
domain={{ y: [0, 30000] }}
/>
</VictoryChart>)
: (<Text> Loading..</Text>)} </View>
But this isn't working and Throwing an error saying Invariant Violation
ExceptionsManager.js:84 Unhandled JS Exception: Invariant Violation: Invariant Violation: Text strings must be rendered within a component.
[Question:] How Can I fix it and render an entire component inside Ternary expression
Ps: According to this stackoverflow question: This happens when we do inline conditional rendering.
I've seen it before in react-native
.
There are 2 reasons i know of that will throw this error:
null
/ undefined
(not your case i think)</Text>
tag (i think this is it in your case)So remove the spaces in the end:
<View style={container}>
{ this.state.loaded ?
(<VictoryChart
theme={VictoryTheme.material}
>
<VictoryArea
style={{ data: { fill: "#c43a31" } }}
data={this.coinHistoryData}
x="cHT"
y="cHTVU"
domain={{ y: [0, 30000] }}
/>
</VictoryChart>)
: (<Text> Loading..</Text>)} </View> //<--- spaces are here
So this line
: (<Text> Loading..</Text>)} </View>
Should be like this
: (<Text> Loading..</Text>)}</View>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With