Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore][maintenance] upgrade several deps | use react 18 #2404 #2409

Merged
28 changes: 0 additions & 28 deletions .yarn/patches/react-scripts__npm_4.0.2.patch

This file was deleted.

1 change: 0 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"@manaflair/redux-batch": "^1.0.0",
"@types/nanoid": "^2.1.0",
"@types/react": "^16.9.46",
"@types/react-redux": "^7.1.9",
"@types/redux-logger": "^3.0.8",
"async-mutex": "^0.3.2",
"axios": "^0.20.0",
Expand Down
12 changes: 9 additions & 3 deletions docs/rtk-query/usage/migrating-to-rtk-query.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ export const selectDataByName = (state: RootState, name: string) =>
state.pokemon.dataByName[name]

// file: src/store.ts noEmit
import { useDispatch } from 'react-redux'
import { EnhancedStore } from '@reduxjs/toolkit'
interface Pokemon {}
type RequestState = 'pending' | 'fulfilled' | 'rejected'

Expand All @@ -221,10 +223,14 @@ export type RootState = {
pokemon: typeof initialPokemonSlice
}

export declare const store: EnhancedStore<RootState>
export type AppDispatch = typeof store.dispatch
export declare const useAppDispatch: () => (...args: any[])=> any;

// file: src/hooks.ts
import { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { RootState } from './store'
import { useSelector } from 'react-redux'
import { RootState, useAppDispatch } from './store'
import {
fetchPokemonByName,
selectStatusByName,
Expand All @@ -233,7 +239,7 @@ import {

// highlight-start
export function useGetPokemonByNameQuery(name: string) {
const dispatch = useDispatch()
const dispatch = useAppDispatch()
// select the current status from the store state for the provided name
const status = useSelector((state: RootState) =>
selectStatusByName(state, name)
Expand Down
4 changes: 3 additions & 1 deletion examples/action-listener/counter/.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
SKIP_PREFLIGHT_CHECK=true
SKIP_PREFLIGHT_CHECK=true
# https://github.com/facebook/create-react-app/issues/11940
DISABLE_ESLINT_PLUGIN=true
23 changes: 14 additions & 9 deletions examples/action-listener/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"dependencies": {
"@reduxjs/toolkit": "^1.8.0",
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react": "^18.0.12",
"@types/react-dom": "^18.0.5",
"clsx": "1.1.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "7.2.2",
"react-scripts": "4.0.3",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-redux": "^8.0.2",
"react-scripts": "5.0.1",
"typescript": "~4.2.4"
},
"scripts": {
Expand All @@ -22,9 +22,11 @@
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"react-app"
],
"rules": {
"react/react-in-jsx-scope": "off"
}
},
"browserslist": {
"production": [
Expand All @@ -37,5 +39,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"jest-watch-typeahead": "^1.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FormEvent } from 'react'
import { ChangeEvent } from 'react-redux/node_modules/@types/react'
import { FormEvent, ChangeEvent } from 'react'
import { useAppDispatch, useAppSelector } from '../../store'
import { themeActions, ThemeState } from '../../services/theme/slice'
import styles from './changeThemeForm.module.css'
Expand Down
6 changes: 4 additions & 2 deletions examples/action-listener/counter/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactDOM from 'react-dom'
import ReactDOM from 'react-dom/client'
import './index.css'
import { store } from './store'
import { themeActions } from './services/theme/slice'
Expand All @@ -8,4 +8,6 @@ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
store.dispatch(themeActions.changeColorScheme('dark'))
}

ReactDOM.render(<App />, document.getElementById('root'))
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)

root.render(<App />)
3 changes: 2 additions & 1 deletion examples/query/react/advanced/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SKIP_PREFLIGHT_CHECK=true
SKIP_PREFLIGHT_CHECK=true
DISABLE_ESLINT_PLUGIN=true
13 changes: 6 additions & 7 deletions examples/query/react/advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
"main": "src/index.tsx",
"dependencies": {
"@reduxjs/toolkit": "^1.6.0-rc.1",
"react": "17.0.0",
"react-dom": "17.0.0",
"react-redux": "7.2.2",
"react-scripts": "4.0.2"
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-redux": "^8.0.2",
"react-scripts": "5.0.1"
},
"devDependencies": {
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"@types/react-redux": "7.1.9",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
},
"eslintConfig": {
Expand Down
11 changes: 6 additions & 5 deletions examples/query/react/advanced/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { render } from 'react-dom'
import ReactDOM from 'react-dom/client'
import { ApiProvider } from '@reduxjs/toolkit/query/react'

import App from './App'
import { pokemonApi } from './services/pokemon'

const rootElement = document.getElementById('root')
render(

const reactRoot = ReactDOM.createRoot(rootElement as HTMLElement)

reactRoot.render(
<ApiProvider api={pokemonApi}>
<App />
</ApiProvider>,
rootElement
</ApiProvider>
)
4 changes: 3 additions & 1 deletion examples/query/react/authentication-with-extrareducers/.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
SKIP_PREFLIGHT_CHECK=true
SKIP_PREFLIGHT_CHECK=true
# https://github.com/facebook/create-react-app/issues/11940
DISABLE_ESLINT_PLUGIN=true
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
"@reduxjs/toolkit": "^1.6.0-rc.1",
"framer-motion": "^2.9.5",
"msw": "^0.41.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-icons": "3.11.0",
"react-redux": "^7.2.4",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.2"
"react-redux": "^8.0.2",
"react-router-dom": "6.3.0",
"react-scripts": "5.0.1"
},
"devDependencies": {
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"@types/react-redux": "7.1.9",
"@types/react-router-dom": "5.1.6",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Switch, Route } from 'react-router-dom'
import { Routes, Route } from 'react-router-dom'
import { Box, Center, VStack } from '@chakra-ui/react'

import { Login } from './features/auth/Login'
import { PrivateRoute } from './utils/PrivateRoute'
import { PrivateOutlet } from './utils/PrivateOutlet'
import { ProtectedComponent } from './features/auth/ProtectedComponent'

function Hooray() {
Expand All @@ -21,12 +21,12 @@ function Hooray() {
function App() {
return (
<Box>
<Switch>
<Route exact path="/login" component={Login} />
<PrivateRoute path="/">
<Hooray />
</PrivateRoute>
</Switch>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/" element={<PrivateOutlet />}>
<Route index element={<Hooray />} />
</Route>
</Routes>
</Box>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Box,
useToast,
} from '@chakra-ui/react'
import { useHistory } from 'react-router-dom'
import { useNavigate } from 'react-router-dom'
import { useDispatch } from 'react-redux'

import { ProtectedComponent } from './ProtectedComponent'
Expand Down Expand Up @@ -47,7 +47,7 @@ function PasswordInput({

export const Login = () => {
const dispatch = useDispatch()
const { push } = useHistory()
const navigate = useNavigate()
const toast = useToast()

const [formState, setFormState] = React.useState<LoginRequest>({
Expand Down Expand Up @@ -86,7 +86,7 @@ export const Login = () => {
// Being that the result is handled in extraReducers in authSlice,
// we know that we're authenticated after this, so the user
// and token will be present in the store
push('/')
navigate('/')
} catch (err) {
toast({
status: 'error',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import ReactDOM from 'react-dom'
import ReactDOM from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import { ChakraProvider } from '@chakra-ui/react'

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

// Initialize the msw worker, wait for the service worker registration to resolve, then mount
worker.start({ quiet: true }).then(() =>
ReactDOM.render(
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<Provider store={store}>
<ChakraProvider>
Expand All @@ -20,7 +20,6 @@ worker.start({ quiet: true }).then(() =>
</BrowserRouter>
</ChakraProvider>
</Provider>
</React.StrictMode>,
document.getElementById('root')
</React.StrictMode>
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Navigate, Outlet, useLocation } from 'react-router-dom'
import { useAuth } from '../hooks/useAuth'

export function PrivateOutlet() {
const auth = useAuth()
const location = useLocation()

return auth.user ? (
<Outlet />
) : (
<Navigate to="/login" state={{ from: location }} />
)
}

This file was deleted.

4 changes: 3 additions & 1 deletion examples/query/react/authentication/.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
SKIP_PREFLIGHT_CHECK=true
SKIP_PREFLIGHT_CHECK=true
# https://github.com/facebook/create-react-app/issues/11940
DISABLE_ESLINT_PLUGIN=true
16 changes: 7 additions & 9 deletions examples/query/react/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
"@reduxjs/toolkit": "^1.6.0-rc.1",
"framer-motion": "^2.9.5",
"msw": "^0.41.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-icons": "3.11.0",
"react-redux": "^7.2.4",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.2"
"react-redux": "^8.0.2",
"react-router-dom": "6.3.0",
"react-scripts": "5.0.1"
},
"devDependencies": {
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"@types/react-redux": "7.1.9",
"@types/react-router-dom": "5.1.6",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
},
"scripts": {
Expand Down
Loading