Skip to content

Commit 2426969

Browse files
Updated Readme
1 parent eb49b14 commit 2426969

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

README.md

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# react-confirm
2-
Small library which makes your Dialog component callable.
2+
react-confirm is a lightweight library that simplifies the implementation of confirmation dialogs in React applications by offering a Promise-based API that works seamlessly with async/await syntax, similar to `window.confirm`.
33

4-
This library does not provide any view component. Just adds a callable functionality to your Dialog component like `window.confirm`.
4+
Another key feature of react-confirm is that it doesn't provide a specific view or component for the confirmation dialog, which allows you to easily customize the appearance of the dialog to match your application's design.
55

6-
In the [example](https://github.com/haradakunihiko/react-confirm/tree/master/example), [react-bootstrap](https://react-bootstrap.github.io/components.html#modals) and [material-ui](http://www.material-ui.com/#/components/dialog) are used with.
6+
In the [example](https://github.com/haradakunihiko/react-confirm/tree/master/example), [react-bootstrap](https://react-bootstrap-v3.netlify.app/components/modal/) and [material-ui](http://www.material-ui.com/#/components/dialog) are used with.
77

88
[![npm version](https://badge.fury.io/js/react-confirm.svg)](https://badge.fury.io/js/react-confirm)
99

1010
## Motivation
11-
React is great. And I respect the concept to render the view reactively only by it's state. However, it easily becomes too complex to manage all temporary states like confirmation dialog. The question is... Is it worth to manage them inside your app? I guess the answer is not always yes.
11+
React is a powerful library that allows for reactive rendering based on component state. However, managing temporary states like confirmation dialogs can quickly become complex. The question is: is it worth implementing these states within your app? The answer is not always a clear yes.
1212

1313
## What you can do
14-
With this library,
15-
- 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.
16-
- You can pass arguments to the function and use them inside the dialog component.
17-
- You can get values from the component in the promise.
18-
- There is no limitation in the dialog. You can use input forms, multiple buttons, whatever you want (see demo site).
14+
react-confirm library offers several benefits:
15+
16+
- You can open a dialog component by calling a function without appending it into your React tree. The function returns a promise, allowing you to handle confirmation results with callbacks.
17+
- You can pass arguments to the function and use them inside the dialog component.
18+
- You can retrieve values from the component in the promise.
19+
- The library provides flexibility in designing the dialog. There is no limitation in the type of components you can use, whether it be input forms or multiple buttons. You can even check out the demo site to see examples of how to customize the dialog.
1920

2021
## Demo
2122
https://codesandbox.io/s/react-confirm-with-react-bootstrap-kjju1
2223

2324
## Versions
2425

25-
- React 18+ users should use `react-confirm` version 0.2.x
26+
- React 18+ users should use `react-confirm` version 0.2.x or 0.3.x
2627
- React <=17 users should stick to `react-confirm` version 0.1.x
2728

2829
## Usage
@@ -109,29 +110,37 @@ const handleOnClick2 = async () => {
109110
You can check more complex example in [codesandbox](https://codesandbox.io/s/react-confirm-with-react-bootstrap-kjju1)
110111

111112
## Using with Context
112-
By default, this library appends your component to outside of your app's React component tree. To consume context in your component, you need to put `MountComponent` to your app's tree.
113+
By default, this library renders the confirmation dialog without appending the component to your app's React component tree. While this can be useful, it may cause issues if you need to consume context in your component. To overcome this problem, you can use the `MountPoint` component to include your confirmation dialog within your app's tree, enabling it to access context and other data from the app.
114+
115+
Create your own `createConfirmation` using `createConfirmationCreater` and `createReactTreeMounter`.
113116

114117
```js
115-
import { createConfirmationCreater, createReactTreeMounter, createMountComponent } from 'react-confirm';
118+
import { createConfirmationCreater, createReactTreeMounter, createMountPoint } from 'react-confirm';
116119

117120
const mounter = createReactTreeMounter();
118121

119122
export const createConfirmation = createConfirmationCreater(mounter);
120-
export const MountComponent = createMountComponent(mounter);
123+
export const MountPoint = createMountPoint(mounter);
121124
```
122125

126+
Put `MountPoint` into your React tree.
123127
```js
124128
const YourRootComponent = () => {
125129
return (
126130
<YourContext.Provider>
127-
<MountComponent />
131+
<MountPoint />
128132
<Toolbar />
129133
</YourContext.Provider>
130134
)
131135
}
132136
```
133137

134-
To render into a different part of the DOM, pass dom element to `createReactTreeMounter`. This will changes the physical placement of the DOM node using `createPortal`.
138+
use your `createConfirmation` as usual.
139+
```js
140+
export const confirm = createConfirmation(YourDialog);
141+
```
142+
143+
To render the confirmation dialog within the React component tree but in a different part of the DOM, you can pass a DOM element to the `createReactTreeMounter` function. This will use the `createPortal` method to render the confirmation dialog in the specified DOM element while keeping it within the React component tree.
135144

136145
```js
137146
const mounter = createReactTreeMounter(document.body);

src/mounter/reactTree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function createReactTreeMounter(mountNode) {
2828
}
2929
}
3030

31-
export function createMountComponent(reactTreeMounter) {
31+
export function createMountPoint(reactTreeMounter) {
3232
return () => {
3333
const [confirmComponents, setConfirmComponents] = useState({});
3434

0 commit comments

Comments
 (0)