Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDom Ss
4,339 PointsWhat is being passed where in state/value?
So when I name differently value property, also the props from the form I still get an updated state object and no errors. For example, this does not give me any errors. Why?
`class AddPlayerForm extends Component {
state = {
value2: ''
};
handleValueChange = (e) => {
this.setState(
{ value2: e.target.value }
);
}
render () {
console.log(this.state.value2, 'value')
return (
<form>
<input
type="text"
value1={this.state.value3}
onChange={this.handleValueChange}
placeholder="Enter a player name"
/>
<input
type="submit"
value="Add Player"
/>
</form>
);
}
}`
1 Answer
Zimri Leijen
11,835 PointsonChange={this.handleValueChange}
will call the function handleValueChange
when the text input is changed.
which will trigger this
this.setState(
{ value2: e.target.value }
);
which sets the value2 key in the state to the value of the event that triggered it.
Dom Ss
4,339 PointsDom Ss
4,339 PointsThank you Zimri,
so "value3" from
value1={this.state.value3}
does not have to match to "value2" from
?
Zimri Leijen
11,835 PointsZimri Leijen
11,835 Pointscorrect, I don't even think
value1={this.state.value3}
does anything at all