I am trying to open a confirmation dialog when the button is clicked with React Admin. The button click name is 'handleSendItemsToUpdate'.
However the dialog is not opening.
Please find the code below:
const notify = useNotify();
const [open, setOpen] = React.useState(false);
const handleDialogClose = () => setOpen(false);
const handleSendItemsToUpdate = (props) => {
const handleConfirm = () => {
notify('Stuff is done.');
setOpen(false);
};
setOpen(true);
return (
<Fragment>
<SaveButton {...props} />
<Confirm
isOpen={open}
title="Update View Count"
content="Are you sure you want to reset the views for these items?"
onConfirm={handleConfirm}
onClose={handleDialogClose}
/>
</Fragment>
);
}
...
<Button className={classes.button} onClick={() => handleSendItemsToUpdate(props)}>Send Items To
Update</Button>
Any help is appreciated.
Thanks in advance!
Begum
The Confirm dialog is returned in the handleSendItemsToUpdate
function, which is not rendered in the component (used in the DOM), that's why it cannot be shown.
You can put the return in the function to the return of component, and of course, it is only shown when the open state is true.
You can check for my demo here: https://codesandbox.io/s/peaceful-dewdney-6pil2?file=/src/App.js