我的主Root.js中有一个函数
//Root.js
deleteEmployee = employeeID => {
let employeesList = this.state.employeesList;
employeesList = employeesList.filter(person => person.id !== employeeID);
this.setState({
employeesList,
});
};
const ButtonRemoveEmployee = ({ id }) => {
return (
<AppContext.Consumer>
{context => {
console.log(this.props);
return (
<button
className="employeePanel__list_btn btn-small waves-effect waves-light"
onClick={() => context.deleteEmployee(id)}
>
Usuń pracownika
</button>
);
}}
</AppContext.Consumer>
);
};
当我单击ButtonRemoveEmployee组件中的按钮时,一切正常。但是我想在从数组中删除项目后,使用函数deleteEmployee跟随其他URL。