我有以下两个组件使用的功能:
export const removeItem = (id, cb) => {
try {
const remove = async () => {
await axios.delete(`http://localhost:9000/news/${id}`);
cb();
};
remove();
} catch (e) {
console.log(e)
}
}
我是NewsItemPage组件,我想提供props.history.push('/ news')作为第二个参数,但是此代码不起作用:
<button onClick={() => {removeItem(someId, props.history.push('/news')) }}>remove</button>
非常感谢任何帮助。
答案 0 :(得分:0)
您必须在其周围放置一个函数才能用作回调。
喜欢<button onClick={() => {removeItem(someId, () => {props.history.push('/news')}) }}>remove</button>