I'm new in ReactNative
, I'm getting the error undefined is not a object
in my this.state.rows
I am trying to dynamically add a View
when a user clicks a Button
. I tried using this and instead of using getInitialState
I used constructor(props)
but I keep on having the said error. Here is my code
constructor(props) {
super(props);
this.state = {
rows: [],
};
}
addRow(){
this.state.rows.push(index++)
this.setState({ rows: this.state.rows })
}
render(){
let contactView = () => {
return <View>
<AddComponent />
</View>
}
return(
<View>
<View>
{contactView}
</View>
<TouchableHighlight onPress={ this.addRow } >
<Text>Add</Text>
</TouchableHighlight>
</View>
);
Thank you for your help!