[Dialog] Add imperative methods to display them directly
See original GitHub issueRefer to the call and implementation of the ant-design
dialog box. This solution brings more flexibility and concise code.
Will there be such a solution?
import { Dialog } from "@material-ui/core";
Dialog.show({
type: "info",
title: "Message",
content: "Hello",
onOk: () => { ... }
});
Benchmark
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (5 by maintainers)
Top Results From Across the Web
[Dialog] Add imperative methods to display them directly #24759
Refer to the call and implementation of the ant-design dialog box. This solution brings more flexibility and concise code.
Read more >MUI - How to open Dialog imperatively/programmatically
First create a custom Provider component in this case I'll call DialogProvider . This component will manage a list of Dialog s in...
Read more >How to Implement and Style the Dialog Element | CSS-Tricks
A look from Christian Kozalla on the HTML element and using it to create a nice-looking and accessible modal.
Read more >Windows 7 Dialog Boxes (Design basics) - Win32 apps
A dialog box is a secondary window that allows users to perform a command, asks users a question, or provides users with information...
Read more >Adding AlertDialog with Jetpack Compose to Android apps
This article presents a simple example using Jetpack Compose in a project and how to create an alert dialog that can come in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could you expand a bit on how you would use it and why the existing API cannot be used for that use case?
Offering an imperative API for state updates can be quite problematic since we or React is no longer in control of the semantics of such an update. So these APIs impose quite the maintenance burden and it’s not clear why it is needed considering this is a React library.
@CarbonPool most likely you want imperative handler(s) to be set on the instance of the dialog component rather than relying on static methods, for example:
@oliviertassinari BTW, it might be a good idea to add
.open()
method to the Dialog’s ref out of the box which should be a small tweak without any breaking changes.https://github.com/kriasoft/react-starter-kit/discussions/2004
Alternatively, with
<DialogProvider>
anduseDialog()
hook, it may look like this:By default, the
DialogProvider
can mount a single instance of the target dialog when used on multiple screens, and if a new instance of the dialog is needed, it can be done by passingkey={...}
with a unique value to the dialog props.Alternatively, the
useDialog()
hook can operate without a need to add<DialogProvider>
upstream like this: