微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

确认对话框没有打开 react-admin

如何解决确认对话框没有打开 react-admin

当使用 React Admin 单击按钮时,我试图打开一个确认对话框。按钮点击名称是“handleSendItemsToUpdate”。

但是对话框没有打开。

请在下面找到代码

  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>

感谢任何帮助。

提前致谢!

贝古姆

解决方法

Confirm 对话框在 handleSendItemsToUpdate 函数中返回,该函数未在组件中呈现(在 DOM 中使用),这就是它无法显示的原因。

可以把函数中的return 放到component的return中,当然只有open状态为true时才会显示。

您可以在这里查看我的演示:https://codesandbox.io/s/peaceful-dewdney-6pil2?file=/src/App.js

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。