Answer the question
In order to leave comments, you need to log in
React how not to overwrite nested object in state?
Parent component has state initialization
state = {
tasks: {},
users: {
userId: 1,
userName: "Artem Gavrilov",
},
appData: {
selectedDate: new Date(),
unfinished: {},
},
};
export default class Form extends React.Component {
handleTextChange = (e) => {
e.preventDefault();
const {name, value} = e.target;
this.setState({...this.state, appData: {
unfinished: {
[name]: value,
}
}
});
}
render() {
return (
<div className="task-container">
<form className="task-form">
<div className="task-line">
<p className="task-p">Название задачи</p>
<input onChange={this.handleTextChange} className="task-input" type="text" required name="taskName"/>
</div>
<div className="task-line">
<p className="task-p">Описание задачи</p>
<textarea onChange={this.handleTextChange} className="task-textarea" cols="20" rows="5" type="text" required name="taskDesc"/>
</div>
</form>
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question