grd
April 26, 2022, 11:30am
1
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:
Manage State Locally First
Hints
Hint 1
Bind the method calls in component attributes with this, e.g.
<input onChange={this.handleChange.bind(this)} value={this.state.input}/>
or the binding can be done beforehand
Hint 2
Pass event to handleChange() method declaration and note that event.target.value stores the input value.
Hint 3
You may wanna add the following <div> into render content to check if the handleChange() method is working.
<div>{this.state.input}</div>
Hint 4
spread operator…
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.
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
grd
April 26, 2022, 12:17pm
3
Thank you very much, I understand! <3
system
Closed
October 26, 2022, 12:17am
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.