|
2 | 2 | title: Migrating to V3 |
3 | 3 | --- |
4 | 4 |
|
5 | | -React Dialog Async V3 introduces a number of breaking changes, however most of these require minimal effort to migrate. |
| 5 | +Introducing React Dialog Async V3! This new major version includes an improved API, new features for more flexible use, |
| 6 | +and much more polished documentation. |
| 7 | + |
| 8 | +## Why V3? |
| 9 | +React Dialog Async started out as a small library for personal use, first published over 4 years ago. At the time I was focused |
| 10 | +on a small set of features for solving my own personal use case. Over time it's grown to support a wider range of use cases, but |
| 11 | +the core API has remained largely unchanged since day one. |
| 12 | + |
| 13 | +Over time as the library has matured, I've started to disagree with some of the original decisions I made. I've held off making |
| 14 | +any breaking changes, but I feel that now is the right time to pay down some technical debt, and bundle all of the breaking changes |
| 15 | +together into a newer, more polished version of the library. |
| 16 | + |
| 17 | +[//]: # (# New Features) |
| 18 | + |
| 19 | +[//]: # () |
| 20 | +[//]: # (## Static Dialogs) |
| 21 | + |
| 22 | +[//]: # () |
| 23 | +[//]: # (## Lazy Loading) |
| 24 | + |
| 25 | +## Breaking Changes |
| 26 | + |
| 27 | +### `show` and `hide` methods removed from `useDialog()` |
| 28 | + |
| 29 | +The methods returned by `useDialog()` have changed. `show` and `hide` were deprecated in `2.4.0`, and have been removed in `3.0.0` in favour of `open` and `close`. |
| 30 | + |
| 31 | +```diff lang="tsx" |
| 32 | + |
| 33 | +const myDialog = useDialog(MyDialog); |
| 34 | + |
| 35 | +-await myDialog.show(...); |
| 36 | ++await myDialog.open(...); |
| 37 | + |
| 38 | +-await myDialog.hide(); |
| 39 | ++await myDialog.close(); |
| 40 | + |
| 41 | +``` |
| 42 | + |
| 43 | +### Updated Options for `useDialog()` |
| 44 | + |
| 45 | +* `customKey` has been removed. This option was not used internally, and was a legacy option from early versions of the library. |
| 46 | + |
| 47 | +* `hideOnHookUnmount` has been renamed to `persistOnUnmount`. This should be more intuitive, as setting this option to `true` will persist the dialog when the hook unmounts. |
| 48 | + |
| 49 | +```diff lang="tsx" |
| 50 | + |
| 51 | +const myDialog = useDialog(MyDialog, { |
| 52 | +- customKey: 'my-dialog', |
| 53 | + |
| 54 | +- hideOnHookUnmount: false |
| 55 | ++ persistOnUnmount: true |
| 56 | +}); |
| 57 | + |
| 58 | +``` |
| 59 | + |
| 60 | +### `<DialogOutlet/>` is now required |
| 61 | + |
| 62 | +In previous versions of the library, `<DialogOutlet/>` was optional, and if it was not required, dialogs would be rendered as children of the `<DialogProvider/>`. |
| 63 | + |
| 64 | +In V3, this is not longer the case, and `<DialogOutlet/>` is now required for dialogs to render. If one is not found, an error will be thrown when attempting to open a dialog. |
| 65 | + |
| 66 | +```diff lang="tsx" |
| 67 | + |
| 68 | +<DialogProvider> |
| 69 | + <App /> |
| 70 | ++ <DialogOutlet /> |
| 71 | +</DialogProvider> |
| 72 | +``` |
| 73 | + |
| 74 | +### `mounted` prop removed from dialog components |
| 75 | +The `mounted` prop passed to dialog components has been removed. This prop was always set to `true`, which made it effectively useless. |
| 76 | + |
| 77 | +```diff lang="tsx" |
| 78 | +- export const MyDialog = ({ mounted }: AsyncDialogProps) => { |
| 79 | ++ export const MyDialog = ({ }: AsyncDialogProps) => { |
| 80 | +// ... |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### `open` and `focused` props renamed to `isOpen` and `isFocused` |
| 85 | +The `open` and `focused` props passed to dialog components have been renamed to `isOpen` and `isFocused` respectively. This is to make it more clear that these props are booleans, and to differentiate them from the `open()` method returned by `useDialog()`. |
| 86 | + |
| 87 | +```diff lang="tsx" |
| 88 | +- export const MyDialog = ({ open, focused }: AsyncDialogProps) => { |
| 89 | ++ export const MyDialog = ({ isOpen, isFocused }: AsyncDialogProps) => { |
| 90 | +// ... |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +### defaultUnmountDelayInMs now defaults to 300ms |
| 95 | + |
| 96 | +The `defaultUnmountDelayInMs` option for `<DialogProvider/>` now defaults to `300`. This is to provide a better out-of-the-box experience, as most dialogs will have some form of exit animation. |
| 97 | + |
| 98 | +If you want to retain the previous behaviour, explicitly set this option to `0`. |
| 99 | +```diff lang="tsx" |
| 100 | +<DialogProvider |
| 101 | ++ defaultUnmountDelayInMs={0} |
| 102 | +/> |
0 commit comments