react-confirm
Small library which makes your Dialog component callable.
This library does not provide any view component. Just adds a functionality to be callable like window.confirm.
In the example, react-bootstrap and material-ui are used with.
Motivation
React is great. And I respect the concept to render the view reactively only by it's state. However, it easily becomes really complex to manage all states which are only needed just temporarily like confirmation dialog. The question is... Is it worth to manage them inside your app? I guess the answer is not always yes.
What you can do
With this library,
- You can open a dialog component by calling function and it will be rendered outside your application. The function returns promise so that you can define callbacks to handle the confirmation result.
- You can pass arguments to the function and use them inside the dialog component.
- You can get values from the component in the promise.
- There is no limitation in the dialog. You can use input forms, multiple buttons, whatever you want .
Usage
- create your dialog component.
- apply
confirmable
to your component (optional, but usually recommended). - create function with
createConfirmation
by passing your confirmable component. - call it!
create confirmable component
create confirm function
call it!
Try example
cd example/react-bootstrap # or cd example/material-ui
npm install
npm run build
npm start