the goal of this app is to insert the TextInputs and the state of color in an array called listPeople by clicking the Button represented below through the submitItem , the TextInputs are name and lastName which I get from the component and color I get from this.props.route.params. I put a console.log to see what's wrong and the problem is that when I launch the code in the terminal it gives me back just the color output like I represented below, which is not even in the form of an array.
Terminal
blue
Screen
export class List extends Component {
constructor(props) {
super(props);
this.state = {
listPeople: [],
name: '',
lastName: '',
color: '',
};
}
submitItem = ( list ) => {
const listPerson = {
color: this.props.route.params,
name: name,
lastName: lastName,
};
this.setState({ listPeople: [...this.state.listPeople, listPerson]})
console.log(listPeople)
};
render() {
const { color } = this.props.route.params;
return (
<Container>
<Header>
<Button transparent>
<Icon
name="checkmark"
onPress={() =>
this.submitItem(
color,
this.state.name,
this.state.lastName,
)
}
/>
</Button>
</Header>
<View style={{ alignItems: "center" }}>
<TextInput
placeholder="name"
textAlign="center"
onChangeText={(name) => this.setState({ name })}
/>
<TextInput
placeholder="lastName"
textAlign="center"
onChangeText={(lastName) => this.setState({ lastName })}
/>
</View>