-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
[DRAFT] Revamp "Redux Essentials" tutorial to be TS-first and update contents #4706
base: master
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
✅ Deploy Preview for redux-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
d107755
to
36dfbeb
Compare
b638fb2
to
8aa8994
Compare
```ts title="features/posts/postsSlice.ts" | ||
// highlight-start | ||
// Import the `PayloadAction` TS type | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | |
import type { PayloadAction } from '@reduxjs/toolkit' | |
import { createSlice } from '@reduxjs/toolkit' |
Explicit type imports could help better distinguish between TS/JS related material on a quick glance.
```js title="features/posts/postsSlice.js" | ||
```ts title="features/posts/postsSlice.ts" | ||
// highlight-next-line | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | |
import type { PayloadAction } from '@reduxjs/toolkit' | |
import { createSlice } from '@reduxjs/toolkit' |
```js title="features/users/usersSlice.js" | ||
import { createSlice } from '@reduxjs/toolkit' | ||
```ts title="features/users/usersSlice.ts" | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | |
import type { PayloadAction } from '@reduxjs/toolkit' | |
import { createSlice } from '@reduxjs/toolkit' |
```jsx title="features/posts/ReactionButtons.js" | ||
import React from 'react' | ||
```ts | ||
import { createSlice, nanoid, PayloadAction } from '@reduxjs/toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { createSlice, nanoid, PayloadAction } from '@reduxjs/toolkit' | |
import type { PayloadAction } from '@reduxjs/toolkit' | |
import { createSlice, nanoid } from '@reduxjs/toolkit' |
In this case, our auth state is really just the current logged-in username, and we'll reset it to `null` if they log out. | ||
```ts title="features/auth/authSlice.ts" | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | |
import type { PayloadAction } from '@reduxjs/toolkit' | |
import { createSlice } from '@reduxjs/toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may apply the type
import change near the end, but I'm honestly not worried about that for now
Given that, we can import the `userLoggedOut` action from `authSlice.ts` into `postsSlice.ts`, listen for that action inside of `postsSlice.extraReducers`, and return an empty posts array to reset the posts list on logout: | ||
```ts title="features/posts/postsSlice.ts" | ||
import { createSlice, nanoid, PayloadAction } from '@reduxjs/toolkit' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { createSlice, nanoid, PayloadAction } from '@reduxjs/toolkit' | |
import type { PayloadAction } from '@reduxjs/toolkit' | |
import { createSlice, nanoid } from '@reduxjs/toolkit' |
6689b10
to
8bd4f9b
Compare
Actual content changes for #4393 , at long last!
The current WIP example code is over in:
I'm doing another round of revisions and step-by-step checking to those code commits as I rework the tutorial content, but that should be the progression and code content I want to show off in the tutorial.
Big picture summary:
createListenerMiddleware
and thunks increateSlice