chunkai1312 / muibox

Promise-based dialog boxes (alert, confirm, prompt) using Material-UI

Home Page:https://chunkai1312.github.io/muibox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to chained dialogs

comxd opened this issue · comments

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

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

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...