I'm new to React and Redux also. I want to remove item from the list so I dispatch an action deleteSelectedItems
then I use redux middleware to catch it and show confirm. That looks like below:
Action:
export const deleteSelectedItems = () => {
return {
type: ActionTypes.ITEM.DELETE_SELECTED,
payload: {
confirm: {
message: 'Are you sure you want to delete these selected items?'
}
}
}
};
Middleware:
const confirmMiddleware = store => next => action => {
if (action.payload.confirm) {
if (confirm(action.payload.confirm.message)) {
next(action);
}
} else {
next(action);
}
};
Everything works well. Now, I don't want to use confirm()
to show confirm dialog, I want to use my own ConfirmDialog
component instead.
I found @Dan Abramov solution, that is great. But I am confused how to integrate those together. I want to use confirmMiddleware
to dispatch an action that show modal but I don't know how to handle when user click ok or cancel on modal. How can I do that?