0
我试图更新状态时,新的员工数据输入。但推功能没有插入新的员工数据的状态。在addpar函数我已经设置了console.log和它结果表明,数据是有,但它不能推陈述状态没有反应
// this class will hold the table and the form
class EmpContainer extends React.Component{
constructor(props) {
super(props);
// the state will have the following data by default
this.state = {participants : [
{ id: '1',
name: 'Dani',
email: '[email protected]',
phone: '0443322118'
},
{ id: '2',
name: 'Dani',
email: '[email protected]',
phone: '0443322118'
}
]};
}
// this supposed to add the new employed data to the state
addPar (emp){
console.log(emp); // this shows the new employee data
this.state.participants.push(emp);
this.setState({
participants: this.state.participants
});}
render() {
return (
<div>
<AddNewParticipant addNew={this.addPar}/>
</div>
);}
}
'使用状态正确'+1 –