Skip to content

Commit

Permalink
[examples] Update to use React 18's createRoot (#32506)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored May 11, 2022
1 parent 0dad28e commit 0d37ced
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/cdn/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@
);
}

ReactDOM.render(
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<App />
</ThemeProvider>,
document.querySelector('#root'),
);
</script>
</body>
Expand Down
12 changes: 12 additions & 0 deletions examples/create-react-app-with-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
8 changes: 5 additions & 3 deletions examples/create-react-app-with-typescript/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider } from '@mui/material/styles';
import App from './App';
import theme from './theme';

ReactDOM.render(
const rootElement = document.getElementById('root');
const root = createRoot(rootElement!);

root.render(
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<App />
</ThemeProvider>,
document.querySelector('#root'),
);
12 changes: 12 additions & 0 deletions examples/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,17 @@
"react": "latest",
"react-dom": "latest",
"react-scripts": "latest"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
8 changes: 5 additions & 3 deletions examples/create-react-app/src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider } from '@mui/material/styles';
import App from './App';
import theme from './theme';

ReactDOM.render(
const rootElement = document.getElementById('root');
const root = createRoot(rootElement);

root.render(
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<App />
</ThemeProvider>,
document.querySelector('#root'),
);
12 changes: 12 additions & 0 deletions examples/joy-cra-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
7 changes: 5 additions & 2 deletions examples/joy-cra-typescript/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import App from './App';

ReactDOM.render(<App />, document.querySelector('#root'));
const rootElement = document.getElementById('root');
const root = createRoot(rootElement!);

root.render(<App />);
8 changes: 5 additions & 3 deletions examples/tailwind-css/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { StyledEngineProvider } from '@mui/material/styles';
import { CssBaseline } from '@mui/material';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
const rootElement = document.getElementById('root');
const root = createRoot(rootElement!);

root.render(
<React.StrictMode>
<StyledEngineProvider injectFirst>
<CssBaseline />
<App />
</StyledEngineProvider>
</React.StrictMode>,
document.getElementById('root'),
);

// If you want to start measuring performance in your app, pass a function
Expand Down
2 changes: 1 addition & 1 deletion examples/vitejs/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function App() {
<Container maxWidth="sm">
<Box sx={{ my: 4 }}>
<Typography variant="h4" component="h1" gutterBottom>
Vite.js v5-beta example
Vite.js example
</Typography>
<ProTip />
<Copyright />
Expand Down
8 changes: 5 additions & 3 deletions examples/vitejs/src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import CssBaseline from '@mui/material/CssBaseline';
import { ThemeProvider } from '@mui/material/styles';
import App from './App';
import theme from './theme';

ReactDOM.render(
const rootElement = document.getElementById('root');
const root = createRoot(rootElement);

root.render(
<React.StrictMode>
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
Expand All @@ -14,5 +17,4 @@ ReactDOM.render(
</ThemeProvider>
,
</React.StrictMode>,
document.getElementById('root'),
);

0 comments on commit 0d37ced

Please sign in to comment.