Skip to content

Commit b9cd32a

Browse files
authored
Support for React 18 (#65)
* #64 Support for React 18 * #64 updated version * #64 updated readme
1 parent d4103aa commit b9cd32a

File tree

13 files changed

+1377
-5905
lines changed

13 files changed

+1377
-5905
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ npm install mui-modal-provider # or yarn add mui-modal-provider
1717

1818
```jsx
1919
import React from 'react';
20-
import ReactDOM from 'react-dom';
20+
import { createRoot } from 'react-dom/client';
2121
import ModalProvider, { useModal } from 'mui-modal-provider';
2222
import Dialog, { DialogProps } from '@mui/material/Dialog';
2323
import DialogTitle from '@mui/material/DialogTitle';
2424
import Button from '@mui/material/Button';
2525

26-
type Props = DialogProps & {
26+
interface SimpleDialogProps extends DialogProps {
2727
title: string,
2828
};
2929

30-
// ✔️ create the dialog you want to use
31-
const SimpleDialog: React.FC<Props> = ({ title, ...props }) => (
30+
// Create the dialog you want to use
31+
const SimpleDialog: React.FC<SimpleDialogProps> = ({ title, ...props }) => (
3232
<Dialog {...props}>
3333
<DialogTitle>{title}</DialogTitle>
3434
</Dialog>
3535
);
3636

37-
// ✔️ use modal hook and show the dialog
37+
// Use modal hook and show the dialog
3838
const App = () => {
3939
const { showModal } = useModal();
4040

@@ -49,12 +49,14 @@ const App = () => {
4949
);
5050
};
5151

52-
// ✔️ wrap the app with modal provider
53-
ReactDOM.render(
52+
const container = document.getElementById('root');
53+
const root = createRoot(container);
54+
55+
// Wrap the app with modal provider
56+
root.render(
5457
<ModalProvider>
5558
<App />
56-
</ModalProvider>,
57-
document.getElementById('root')
59+
</ModalProvider>
5860
);
5961
```
6062

coverage/coverage-final.json

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.

example/package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
"build": "parcel build ./src/index.html"
99
},
1010
"dependencies": {
11-
"@emotion/react": "^11.7.0",
12-
"@emotion/styled": "^11.6.0",
13-
"@mui/material": "^5.2.3",
14-
"react-app-polyfill": "^1.0.0"
11+
"@emotion/react": "^11.10.0",
12+
"@emotion/styled": "^11.10.0",
13+
"@mui/material": "^5.9.3",
14+
"react-app-polyfill": "^3.0.0"
1515
},
1616
"alias": {
1717
"react": "../node_modules/react",
18-
"react-dom": "../node_modules/react-dom/profiling",
18+
"react-dom": "../node_modules/react-dom",
19+
"react-dom/client": "../node_modules/react-dom/client",
1920
"scheduler/tracing": "../node_modules/scheduler/tracing-profiling"
2021
},
2122
"devDependencies": {
22-
"@types/react": "^17.0.6",
23-
"@types/react-dom": "^17.0.5",
24-
"parcel": "^2.0.0-beta.2",
25-
"typescript": "^3.4.5"
23+
"@types/react": "^18.0.15",
24+
"@types/react-dom": "^18.0.6",
25+
"parcel": "^2.7.0",
26+
"typescript": "^4.7.4"
2627
}
2728
}

example/src/components/dialogs/confirmation-dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import DialogContentText from '@mui/material/DialogContentText';
66
import Dialog, { DialogProps } from '@mui/material/Dialog';
77
import Button from '@mui/material/Button';
88

9-
type Props = DialogProps & {
9+
export interface ConfirmationDialogProps extends DialogProps {
1010
title: string;
1111
description: string;
1212
onCancel: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
1313
onConfirm: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
1414
};
1515

16-
const ConfirmationDialog: React.FC<Props> = ({
16+
const ConfirmationDialog: React.FC<ConfirmationDialogProps> = ({
1717
title,
1818
description,
1919
onCancel,

example/src/components/dialogs/nested-dialog.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import DialogActions from '@mui/material/DialogActions';
66
import Button from '@mui/material/Button';
77
import { useModal } from '../../../../src';
88

9-
type Props = DialogProps & {
10-
// nesting level
9+
export interface NestedDialogProps extends DialogProps {
1110
deep: number;
1211
};
1312

14-
const NestedDialog: React.FC<Props> = ({ deep = 0, ...props }) => {
13+
const NestedDialog: React.FC<NestedDialogProps> = ({ deep = 0, ...props }) => {
1514
const { showModal } = useModal();
1615

1716
const handleClick = () => {

example/src/components/modals/simple-modal.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react';
22
import Box from '@mui/material/Box';
33
import Modal, { ModalProps } from '@mui/material/Modal';
4+
import { SxProps, Theme } from '@mui/material/styles';
45

5-
const style = {
6+
const style: SxProps<Theme> = {
67
position: 'absolute',
78
width: 400,
89
top: '50%',
@@ -13,9 +14,9 @@ const style = {
1314
p: 4,
1415
};
1516

16-
type Props = Omit<ModalProps, 'children'> & {};
17+
export interface SimpleModalProps extends Omit<ModalProps, 'children'> {};
1718

18-
const SimpleModal: React.FC<Props> = props => (
19+
const SimpleModal: React.FC<SimpleModalProps> = props => (
1920
<Modal {...props}>
2021
<Box sx={style}>
2122
<h2>Simple Modal</h2>

example/src/components/modals/transition-modal.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import Fade from '@mui/material/Fade';
55
import Box from '@mui/material/Box';
66
import Typography from '@mui/material/Typography';
77
import { TransitionProps } from '@mui/material/transitions';
8+
import { SxProps, Theme } from '@mui/material/styles';
89

9-
const style = {
10+
const style: SxProps<Theme> = {
1011
position: 'absolute',
1112
top: '50%',
1213
left: '50%',
@@ -18,11 +19,11 @@ const style = {
1819
p: 4,
1920
};
2021

21-
type Props = Omit<ModalProps, 'children'> & {
22+
export interface TransitionsModalProps extends Omit<ModalProps, 'children'> {
2223
TransitionProps: TransitionProps;
2324
};
2425

25-
export default function TransitionsModal({ open, ...props }: Props) {
26+
export default function TransitionsModal({ open, ...props }: TransitionsModalProps) {
2627
/**
2728
* 💡 if you are using material-ui before version 5,
2829
* then you should use `onExited` (and other methods) directly from props.

example/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
<body>
1111
<div id="root"></div>
12-
<script src="./index.tsx"></script>
12+
<script type="module" src="./index.tsx"></script>
1313
</body>
1414
</html>

example/src/index.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import * as ReactDOM from 'react-dom';
2+
import * as ReactDOM from 'react-dom/client';
33
import {
44
StyledEngineProvider,
55
ThemeProvider,
@@ -10,14 +10,18 @@ import ModalProvider from '../../src';
1010
import App from './app';
1111

1212
const theme = createTheme();
13+
const container = document.getElementById('root');
1314

14-
ReactDOM.render(
15-
<StyledEngineProvider injectFirst>
16-
<ThemeProvider theme={theme}>
17-
<ModalProvider>
18-
<App />
19-
</ModalProvider>
20-
</ThemeProvider>
21-
</StyledEngineProvider>,
22-
document.getElementById('root')
23-
);
15+
if (container) {
16+
const root = ReactDOM.createRoot(container);
17+
18+
root.render(
19+
<StyledEngineProvider injectFirst>
20+
<ThemeProvider theme={theme}>
21+
<ModalProvider>
22+
<App />
23+
</ModalProvider>
24+
</ThemeProvider>
25+
</StyledEngineProvider>
26+
);
27+
}

0 commit comments

Comments
 (0)