Question FrontEndDev, React+Redux: Manage State Locally First

Hello my dear Campers,

I’ve got a question to the “Manage State Locally First” challenge, or more to the guide written in the forum, somehow I couldn’t comment it:

Why would we take care for the messages-key in the handleChange() → setState() function ?

I can comment it out and the code still runs.
//messages: this.state.messages

Is it more a convention to do this ?

Iam afraid I just have a slight mind-hiccups, or I forgot something important from the react-challenges. :face_with_open_eyes_and_hand_over_mouth: :sweat: :slightly_smiling_face:

Many greetings to you people !

1 Like

You shouldn’t deal with the messages there.

This:

  handleChange(event){
    this.setState({
      input: event.target.value,
      messages: this.state.messages
    })
  }

That messages line doesn’t do anything and is completely unneeded. You only need to give the properties you are changing. That is sloppy React. It doesn’t hurt anything, it’s just wasteful. It’s the kind of thing that people write when they’re still learning React.

Keep in mind that the guides are just things that people wrote, they aren’t maintained, and they have to be taken with a grain of salt.

2 Likes

Thank you very much, I understand! <3

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.