Skip to content

Commit 5620e36

Browse files
committed
chore: upgrade react, react-18 & react-router-dom of examples workspaces
1 parent cc7bbfd commit 5620e36

File tree

66 files changed

+494
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+494
-494
lines changed

examples/action-listener/counter/src/components/ChangeThemeForm/ChangeThemeForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { FormEvent } from 'react'
2-
import { ChangeEvent } from 'react-redux/node_modules/@types/react'
1+
import { FormEvent, ChangeEvent } from 'react'
32
import { useAppDispatch, useAppSelector } from '../../store'
43
import { themeActions, ThemeState } from '../../services/theme/slice'
54
import styles from './changeThemeForm.module.css'
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ReactDOM from 'react-dom'
1+
import ReactDOM from 'react-dom/client'
22
import './index.css'
33
import { store } from './store'
44
import { themeActions } from './services/theme/slice'
@@ -8,4 +8,6 @@ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
88
store.dispatch(themeActions.changeColorScheme('dark'))
99
}
1010

11-
ReactDOM.render(<App />, document.getElementById('root'))
11+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
12+
13+
root.render(<App />)
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { render } from 'react-dom'
1+
import ReactDOM from 'react-dom/client'
22
import { ApiProvider } from '@reduxjs/toolkit/query/react'
3-
43
import App from './App'
54
import { pokemonApi } from './services/pokemon'
65

76
const rootElement = document.getElementById('root')
8-
render(
7+
8+
const reactRoot = ReactDOM.createRoot(rootElement as HTMLElement)
9+
10+
reactRoot.render(
911
<ApiProvider api={pokemonApi}>
1012
<App />
11-
</ApiProvider>,
12-
rootElement
13+
</ApiProvider>
1314
)

examples/query/react/authentication-with-extrareducers/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
"react-dom": "^18.1.0",
1717
"react-icons": "3.11.0",
1818
"react-redux": "^8.0.2",
19-
"react-router-dom": "5.2.0",
19+
"react-router-dom": "6.3.0",
2020
"react-scripts": "4.0.2"
2121
},
2222
"devDependencies": {
2323
"@types/react": "^18.0.5",
2424
"@types/react-dom": "^18.0.5",
25-
"@types/react-router-dom": "5.1.6",
2625
"typescript": "~4.2.4"
2726
},
2827
"scripts": {

examples/query/react/authentication-with-extrareducers/src/App.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Switch, Route } from 'react-router-dom'
1+
import { Routes, Route } from 'react-router-dom'
22
import { Box, Center, VStack } from '@chakra-ui/react'
33

44
import { Login } from './features/auth/Login'
5-
import { PrivateRoute } from './utils/PrivateRoute'
5+
import { PrivateOutlet } from './utils/PrivateOutlet'
66
import { ProtectedComponent } from './features/auth/ProtectedComponent'
77

88
function Hooray() {
@@ -21,12 +21,12 @@ function Hooray() {
2121
function App() {
2222
return (
2323
<Box>
24-
<Switch>
25-
<Route exact path="/login" component={Login} />
26-
<PrivateRoute path="/">
27-
<Hooray />
28-
</PrivateRoute>
29-
</Switch>
24+
<Routes>
25+
<Route path="/login" element={<Login />} />
26+
<Route path="/" element={<PrivateOutlet />}>
27+
<Route index element={<Hooray />} />
28+
</Route>
29+
</Routes>
3030
</Box>
3131
)
3232
}

examples/query/react/authentication-with-extrareducers/src/features/auth/Login.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Box,
1111
useToast,
1212
} from '@chakra-ui/react'
13-
import { useHistory } from 'react-router-dom'
13+
import { useNavigate } from 'react-router-dom'
1414
import { useDispatch } from 'react-redux'
1515

1616
import { ProtectedComponent } from './ProtectedComponent'
@@ -47,7 +47,7 @@ function PasswordInput({
4747

4848
export const Login = () => {
4949
const dispatch = useDispatch()
50-
const { push } = useHistory()
50+
const navigate = useNavigate()
5151
const toast = useToast()
5252

5353
const [formState, setFormState] = React.useState<LoginRequest>({
@@ -86,7 +86,7 @@ export const Login = () => {
8686
// Being that the result is handled in extraReducers in authSlice,
8787
// we know that we're authenticated after this, so the user
8888
// and token will be present in the store
89-
push('/')
89+
navigate('/')
9090
} catch (err) {
9191
toast({
9292
status: 'error',

examples/query/react/authentication-with-extrareducers/src/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import ReactDOM from 'react-dom'
2+
import ReactDOM from 'react-dom/client'
33
import { BrowserRouter } from 'react-router-dom'
44
import { ChakraProvider } from '@chakra-ui/react'
55

@@ -11,7 +11,7 @@ import { Provider } from 'react-redux'
1111

1212
// Initialize the msw worker, wait for the service worker registration to resolve, then mount
1313
worker.start({ quiet: true }).then(() =>
14-
ReactDOM.render(
14+
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
1515
<React.StrictMode>
1616
<Provider store={store}>
1717
<ChakraProvider>
@@ -20,7 +20,6 @@ worker.start({ quiet: true }).then(() =>
2020
</BrowserRouter>
2121
</ChakraProvider>
2222
</Provider>
23-
</React.StrictMode>,
24-
document.getElementById('root')
23+
</React.StrictMode>
2524
)
2625
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Navigate, Outlet, useLocation } from 'react-router-dom'
2+
import { useAuth } from '../hooks/useAuth'
3+
4+
export function PrivateOutlet() {
5+
const auth = useAuth()
6+
const location = useLocation()
7+
8+
return auth.user ? (
9+
<Outlet />
10+
) : (
11+
<Navigate to="/login" state={{ from: location }} />
12+
)
13+
}

examples/query/react/authentication-with-extrareducers/src/utils/PrivateRoute.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/query/react/authentication/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
"react-dom": "^18.1.0",
1717
"react-icons": "3.11.0",
1818
"react-redux": "^8.0.2",
19-
"react-router-dom": "5.2.0",
19+
"react-router-dom": "6.3.0",
2020
"react-scripts": "4.0.2"
2121
},
2222
"devDependencies": {
2323
"@types/react": "^18.0.5",
2424
"@types/react-dom": "^18.0.5",
25-
"@types/react-router-dom": "5.1.6",
2625
"typescript": "~4.2.4"
2726
},
2827
"scripts": {

examples/query/react/authentication/src/App.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Switch, Route } from 'react-router-dom'
1+
import { Routes, Route } from 'react-router-dom'
22
import { Box, Center, VStack } from '@chakra-ui/react'
33

44
import { Login } from './features/auth/Login'
5-
import { PrivateRoute } from './utils/PrivateRoute'
5+
import { PrivateOutlet } from './utils/PrivateOutlet'
66
import { ProtectedComponent } from './features/auth/ProtectedComponent'
77

88
function Hooray() {
@@ -21,12 +21,12 @@ function Hooray() {
2121
function App() {
2222
return (
2323
<Box>
24-
<Switch>
25-
<Route exact path="/login" component={Login} />
26-
<PrivateRoute path="/">
27-
<Hooray />
28-
</PrivateRoute>
29-
</Switch>
24+
<Routes>
25+
<Route path="/login" element={<Login />} />
26+
<Route path="/" element={<PrivateOutlet />}>
27+
<Route index element={<Hooray />} />
28+
</Route>
29+
</Routes>
3030
</Box>
3131
)
3232
}

examples/query/react/authentication/src/features/auth/Login.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Box,
1111
useToast,
1212
} from '@chakra-ui/react'
13-
import { useHistory } from 'react-router-dom'
13+
import { useNavigate } from 'react-router-dom'
1414
import { useDispatch } from 'react-redux'
1515
import { setCredentials } from './authSlice'
1616

@@ -48,7 +48,7 @@ function PasswordInput({
4848

4949
export const Login = () => {
5050
const dispatch = useDispatch()
51-
const { push } = useHistory()
51+
const navigate = useNavigate()
5252
const toast = useToast()
5353

5454
const [formState, setFormState] = React.useState<LoginRequest>({
@@ -85,7 +85,7 @@ export const Login = () => {
8585
try {
8686
const user = await login(formState).unwrap()
8787
dispatch(setCredentials(user))
88-
push('/')
88+
navigate('/')
8989
} catch (err) {
9090
toast({
9191
status: 'error',
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import React from 'react'
2-
import ReactDOM from 'react-dom'
2+
import ReactDOM from 'react-dom/client'
33
import { BrowserRouter } from 'react-router-dom'
44
import { ChakraProvider } from '@chakra-ui/react'
5-
65
import App from './App'
76
import { store } from './app/store'
8-
97
import { worker } from './mocks/browser'
108
import { Provider } from 'react-redux'
119

1210
// Initialize the msw worker, wait for the service worker registration to resolve, then mount
13-
worker.start({ quiet: true }).then(() =>
14-
ReactDOM.render(
15-
<React.StrictMode>
16-
<Provider store={store}>
17-
<ChakraProvider>
18-
<BrowserRouter>
19-
<App />
20-
</BrowserRouter>
21-
</ChakraProvider>
22-
</Provider>
23-
</React.StrictMode>,
24-
document.getElementById('root')
25-
)
26-
)
11+
worker
12+
.start({ quiet: true })
13+
.then(() => {
14+
const rootNode = ReactDOM.createRoot(
15+
document.getElementById('root') as HTMLElement
16+
)
17+
18+
return rootNode.render(
19+
<React.StrictMode>
20+
<Provider store={store}>
21+
<ChakraProvider>
22+
<BrowserRouter>
23+
<App />
24+
</BrowserRouter>
25+
</ChakraProvider>
26+
</Provider>
27+
</React.StrictMode>
28+
)
29+
})
30+
.catch(console.error)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Navigate, Outlet, useLocation } from 'react-router-dom'
2+
import { useAuth } from '../hooks/useAuth'
3+
4+
export function PrivateOutlet() {
5+
const auth = useAuth()
6+
const location = useLocation()
7+
8+
return auth.user ? (
9+
<Outlet />
10+
) : (
11+
<Navigate to="/login" state={{ from: location }} />
12+
)
13+
}

examples/query/react/authentication/src/utils/PrivateRoute.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/query/react/basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"react-scripts": "4.0.2"
1414
},
1515
"devDependencies": {
16-
"@testing-library/react": "^12.0.0",
16+
"@testing-library/react": "^13.3.0",
1717
"@types/jest": "^26.0.23",
1818
"@types/react": "^18.0.5",
1919
"@types/react-dom": "^18.0.5",
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import { render } from 'react-dom'
1+
import ReactDOM from 'react-dom/client'
22
import { Provider } from 'react-redux'
33

44
import App from './App'
55
import { setupStore } from './store'
66

77
const store = setupStore()
88

9-
const rootElement = document.getElementById('root')
10-
render(
9+
const reactRoot = ReactDOM.createRoot(
10+
document.getElementById('root') as HTMLElement
11+
)
12+
reactRoot.render(
1113
<Provider store={store}>
1214
<App />
13-
</Provider>,
14-
rootElement
15+
</Provider>
1516
)
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { render } from 'react-dom'
1+
import ReactDOM from 'react-dom/client'
22
import { Provider } from 'react-redux'
33

44
import App from './App'
55
import { store } from './store'
66

7-
const rootElement = document.getElementById('root')
8-
render(
7+
const reactRoot = ReactDOM.createRoot(
8+
document.getElementById('root') as HTMLElement
9+
)
10+
reactRoot.render(
911
<Provider store={store}>
1012
<App />
11-
</Provider>,
12-
rootElement
13+
</Provider>
1314
)

0 commit comments

Comments
 (0)