I have a conditional statement that determines which JSX should be rendered on screen. It looks at an array held in the state, and, if empty, renders an image and some text. However, if populated, the data is rendered using Flat List.
When the conditional statement equates to false (the array is empty) the image and text are rendered very briefly (for around half a second).
How can I alter it so it does not appear at all? As the logic would suggest.
My code is below:
render() {
if (this.state.array === undefined || this.state.array.length === 0) {
return (
<View>
<View>
<Text> Tap the (+) button to add an item.</Text>
<Image source={require('../images/image.png')} />
</View>
</View>
);
}
//If array data
return (
<View>
<FlatList
data={this.state.array}
renderItem={({ item }) => <TrackedItem {...item} />}
keyExtractor={(item, index) => index.toString()}
/>
</View>
);
}