1

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>

1 Answer 1

1

I think it's because you're passing 3 params on your this.submitItem try this :

submitItem = ( color, name, lastName) => {       
        const  listPerson = {
            color: this.props.route.params,
            name: name,
            lastName: lastName,
          };
          this.setState({ listPeople: [...this.state.listPeople, listPerson]})
          console.log(listPeople)
      };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.