new to React Native but I have an array of data
list = [
{key: "image1", imgLink: "imagelink"},
{key: "image2", imgLink: "imagelink"},
{key: "image3", imgLink: "imagelink"},
{key: "image3", imgLink: "imagelink"},
]
which is passed in props to my component and then I put it in state in my constructor
constructor(props){
super(props)
this.state = {
portraitImage: 'initalImageLink',
isModalVisible: false,
list: this.props.list,
};
}
I also have a FlatList inside of a modal:
<Modal isVisible={this.state.isModalVisible} onBackdropPress = {this._hideModal}>
<View style={{ flex: 1, backgroundColor:'#FFFFFF'}}>
<FlatList
data={this.state.list}
renderItem={
({item}) => <ListItem onPress = {this._setImg.bind(this,item.imgLink)} title={item.key} />
}
/>
<Button title = {'Close Modal'} onPress={this._hideModal}/>
</View>
</Modal>
_setImage(value){
this.setState({
portraitImage: value
});
};
I am trying to just show the list of Key names (image1, image2, image3, image4) and then when the user presses one of the key names it will change portraitImage state.
This is what I have right now but my FlatList seems to be blank and show nothing. I dont understand why the list is blank.
When i set data = {this.props.list} instead of state I get
Element type is invalid: expected a string (for built-in components) or >a class/function (for composite components) but got: undefined. You >likely forgot to export your component from the file it's defined in.