chunkai1312 / muibox

Promise-based dialog boxes (alert, confirm, prompt) using Material-UI
https://chunkai1312.github.io/muibox
MIT License
20 stars 6 forks source link

Unable to chained dialogs #12

Open comxd opened 4 years ago

comxd commented 4 years ago

In case of displaying a new dialog inside a callback, the new dialog is correctly displayed but disappear after component is re-rendered.

import React from "react";
import "./styles.css";
import { useDialog } from "muibox";

export default function App() {
  const dialog = useDialog();
  const handlePrompt = () =>
    dialog
      .prompt({
        message: "Fill your Email and click OK button",
        ok: { text: "OK", color: "primary", variant: "contained" },
        cancel: false
      })
      .then(email => dialog.alert(`Your email: ${email}`))
      .catch(() => {});

  return (
    <div className="App">
      <button onClick={handlePrompt}>Click me</button>
    </div>
  );
}

Codesandbox: https://codesandbox.io/s/muibox-13-bug-chained-dialogs-06lo3

chunkai1312 commented 4 years ago

For this example, a simple solution is to use setTimeout() before invoke dialog.alert().

Ark-kun commented 3 years ago

For this example, a simple solution is to use setTimeout() before invoke dialog.alert().

Are you sure that's correct approach? This seems like a bug...