我正在制作一个应用程序,其中我需要制作一个确认框来询问用户是否要删除该记录。我想全局使用确认框。
假设我要删除一条记录,当用户单击删除按钮时,它会执行删除记录的操作。但是,一旦进入删除操作,就会调度另一个操作以显示模态。(到目前为止,我已经达到了)
但是,我在执行应该等待用户单击“确认”或“取消”的部分遇到了困难。用户执行操作后,应继续执行删除记录。
我希望我的问题陈述是明确的。
请让我知道我应该怎么做。我真的很想了解这个东西在 React 中是如何工作的。
目前,我正在使用窗口的确认来询问用户“是”或“否”。
// Delete Profile
export const deleteProfile = (history) => async (dispatch) => {
try {
if (
window.confirm('Are you Sure? Your account would be permanently lost')
) {
await axios.delete(`/api/profile`);
dispatch({ type: actionTypes.CLEAR_PROFILE });
dispatch({ type: actionTypes.ACCOUNT_DELETED });
history.push('/login');
dispatch(
setAlert('Your account has been deleted permanently', 'success')
);
}
} catch (err) {
dispatch(setAlert('Profile deletion error', 'danger'));
}
};
我希望调用一个模式来代替窗口确认并等待用户输入,如果它返回true,我想继续前进,否则中止。
慕森王
梦里花落0921
相关分类