【问题标题】:Confirm dialog is not opening react-admin确认对话框未打开 react-admin
【发布时间】:2021-08-07 14:48:14
【问题描述】:

当使用 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>

感谢任何帮助。

提前致谢!

贝格姆

【问题讨论】:

    标签: react-admin confirm


    【解决方案1】:

    Confirm 对话框在handleSendItemsToUpdate 函数中返回,该对话框没有在组件中呈现(在 DOM 中使用),因此无法显示。

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

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

    【讨论】:

    • 非常感谢 :) 当我将确认放入组件返回时,对话框打开了!!
    • 嗨 Begum,通过将确认(或任何类型的模态)放入 React 中的更好方法,将其放入 组件并使用 redux 管理其打开状态和内容,因此您可以在任何组件的任何位置打开和更新模态中的内容。希望这会有所帮助:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 2021-06-28
    相关资源
    最近更新 更多