diff --git a/docs/api/createSlice.mdx b/docs/api/createSlice.mdx index d6b4269764..53b01a1e4a 100644 --- a/docs/api/createSlice.mdx +++ b/docs/api/createSlice.mdx @@ -304,16 +304,25 @@ Typing for the `create.asyncThunk` works in the same way as [`createAsyncThunk`] A type for `state` and/or `dispatch` _cannot_ be provided as part of the `ThunkApiConfig`, as this would cause circular types. -Instead, it is necessary to assert the type when needed. +Instead, it is necessary to assert the type when needed - `getState() as RootState`. You may also include an explicit return type for the payload function as well, in order to break the circular type inference cycle. ```ts no-transpile create.asyncThunk( - async (id, thunkApi) => { + // highlight-start + // may need to include an explicit return type + async (id: string, thunkApi): Promise => { + // Cast types for `getState` and `dispatch` manually const state = thunkApi.getState() as RootState const dispatch = thunkApi.dispatch as AppDispatch - throw thunkApi.rejectWithValue({ - error: 'Oh no!', - }) + // highlight-end + try { + const todo = await fetchTodo() + return todo + } catch (e) { + throw thunkApi.rejectWithValue({ + error: 'Oh no!', + }) + } } ) ``` diff --git a/docs/api/getDefaultMiddleware.mdx b/docs/api/getDefaultMiddleware.mdx index ef15eca14f..7e51cf618f 100644 --- a/docs/api/getDefaultMiddleware.mdx +++ b/docs/api/getDefaultMiddleware.mdx @@ -55,7 +55,7 @@ const store = configureStore({ // Store has all of the default middleware added, _plus_ the logger middleware ``` -It is preferable to use the chainable `.concat(...)` and `.prepend(...)` methods of the returned `Tuple` instead of the array spread operator, as the latter can lose valuable type information under some circumstances. +It is preferable to use the chainable `.concat(...)` and `.prepend(...)` methods of the returned `Tuple` instead of the array spread operator, as the latter can lose valuable TS type information under some circumstances. ## Included Default Middleware diff --git a/docs/introduction/getting-started.md b/docs/introduction/getting-started.md index 9bb4cfc038..8085db8f3e 100644 --- a/docs/introduction/getting-started.md +++ b/docs/introduction/getting-started.md @@ -34,7 +34,7 @@ you make your Redux code better. ### Create a React Redux App -The recommended way to start new apps with React and Redux is by using [our official Redux+TS template for Vite](https://github.com/reduxjs/redux-templates), or by creating a new Next.js project using [Next's `with-redux` template](https://github.com/vercel/next.js/tree/canary/examples/with-redux). +The recommended way to start new apps with React and Redux Toolkit is by using [our official Redux Toolkit + TS template for Vite](https://github.com/reduxjs/redux-templates), or by creating a new Next.js project using [Next's `with-redux` template](https://github.com/vercel/next.js/tree/canary/examples/with-redux). Both of these already have Redux Toolkit and React-Redux configured appropriately for that build tool, and come with a small example app that demonstrates how to use several of Redux Toolkit's features. @@ -85,8 +85,7 @@ yarn add react-redux -It is also available as a precompiled UMD package that defines a `window.RTK` global variable. -The UMD package can be used as a [`