Skip to content

Commit 0ec8920

Browse files
authored
Improve docs and formatting (#4774)
* Add highlight to the changed lines * Add highlight to the modified code in docs * Add space to the beginning of comments that do not have one * Fix typos
1 parent 6dc1c9c commit 0ec8920

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

docs/tutorials/essentials/part-4-using-data.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ export const selectAllPosts = (state: RootState) => state.posts
476476

477477
export const selectPostById = (state: RootState, postId: string) =>
478478
state.posts.find(post => post.id === postId)
479-
//highlight-end
479+
// highlight-end
480480
```
481481
482482
Note that the `state` parameter for these selector functions is the root Redux state object, as it was for the inlined anonymous selectors we wrote directly inside of `useAppSelector`.
@@ -497,7 +497,7 @@ export const PostsList = () => {
497497
498498
```tsx title="features/posts/SinglePostPage.tsx"
499499
// omit imports
500-
//highlight-next-line
500+
// highlight-next-line
501501
import { selectPostById } from './postsSlice'
502502

503503
export const SinglePostPage = () => {
@@ -511,7 +511,7 @@ export const SinglePostPage = () => {
511511
512512
```ts title="features/posts/EditPostForm.tsx"
513513
// omit imports
514-
//highlight-next-line
514+
// highlight-next-line
515515
import { postUpdated, selectPostById } from './postsSlice'
516516

517517
export const EditPostForm = () => {
@@ -894,11 +894,11 @@ Since `array.sort()` mutates the existing array, we need to make a copy of `stat
894894
895895
```tsx title="features/posts/PostsList.tsx"
896896
// Sort posts in reverse chronological order by datetime string
897-
//highlight-start
897+
// highlight-start
898898
const orderedPosts = posts.slice().sort((a, b) => b.date.localeCompare(a.date))
899899

900900
const renderedPosts = orderedPosts.map(post => {
901-
//highlight-end
901+
// highlight-end
902902
return (
903903
// omit rendering logic
904904
)

docs/tutorials/essentials/part-5-async-logic.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ const initialState: PostsState = {
335335
status: 'idle',
336336
error: null
337337
}
338-
//highlight-end
338+
// highlight-end
339339

340340
const postsSlice = createSlice({
341341
name: 'posts',
@@ -413,7 +413,7 @@ import { createSlice, nanoid, PayloadAction } from '@reduxjs/toolkit'
413413
import { client } from '@/api/client'
414414

415415
import type { RootState } from '@/app/store'
416-
//highlight-next-line
416+
// highlight-next-line
417417
import { createAppAsyncThunk } from '@/app/withTypes'
418418

419419
// omit other imports and types

docs/tutorials/essentials/part-7-rtk-query-basics.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,11 @@ export const PostsList = () => {
747747
if (isLoading) {
748748
content = <Spinner text="Loading..." />
749749
} else if (isSuccess) {
750+
// highlight-start
750751
const renderedPosts = sortedPosts.map(post => (
751752
<PostExcerpt key={post.id} post={post} />
752753
))
754+
// highlight-end
753755

754756
// highlight-start
755757
const containerClassname = classnames('posts-container', {

docs/tutorials/essentials/part-8-rtk-query-advanced.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ export const EditPostForm = () => {
117117
)
118118
}
119119

120+
// highlight-start
120121
const onSavePostClicked = async (
122+
// highlight-end
121123
e: React.FormEvent<EditPostFormElements>
122124
) => {
123125
// Prevent server submission
@@ -410,7 +412,7 @@ export interface User {
410412
name: string
411413
}
412414

413-
// omit `fetchSlice` and `usersSlice`
415+
// omit `fetchUsers` and `usersSlice`
414416

415417
// highlight-start
416418
const emptyUsers: User[] = []
@@ -646,9 +648,9 @@ The last component that is reading from the old `postsSlice` is `<UserPage>`, wh
646648
647649
The `useQuery` hooks always take the cache key argument as the first parameter, and if you need to provide hook options, that must always be the second parameter, like `useSomeQuery(cacheKey, options)`. In this case, the `getUsers` endpoint doesn't have any actual cache key argument. Semantically, this is the same as a cache key of `undefined`. So, in order to provide options to the hook, we have to call `useGetUsersQuery(undefined, options)`.
648650
649-
We can use `selectFromResult` to have `<UserPage>` read just a filtered list of posts from the cache. However, in order for `selectFromResult` to avoid unnecessary re-renders, we need to ensure that whatever data we extract is memoized correctly. To do this, we should create a new selector instance that the `<UsersPage>` component can reuse every time it renders, so that the selector memoizes the result based on its inputs.
651+
We can use `selectFromResult` to have `<UserPage>` read just a filtered list of posts from the cache. However, in order for `selectFromResult` to avoid unnecessary re-renders, we need to ensure that whatever data we extract is memoized correctly. To do this, we should create a new selector instance that the `<UserPage>` component can reuse every time it renders, so that the selector memoizes the result based on its inputs.
650652
651-
```tsx title="features/users/UsersPage.tsx"
653+
```tsx title="features/users/UserPage.tsx"
652654
import { Link, useParams } from 'react-router-dom'
653655
// highlight-start
654656
import { createSelector } from '@reduxjs/toolkit'

docs/tutorials/fundamentals/part-3-state-actions-reducers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ export default function todosReducer(state = initialState, action) {
581581
}
582582
})
583583
}
584-
//highlight-end
584+
// highlight-end
585585
default:
586586
return state
587587
}

docs/usage/ServerRendering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import App from './containers/App'
5555
const app = Express()
5656
const port = 3000
5757

58-
//Serve static files
58+
// Serve static files
5959
app.use('/static', Express.static('static'))
6060

6161
// This is fired every time the server side receives a request

docs/usage/UsageWithTypescript.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ type RootState = ReturnType<typeof rootReducer>;
300300
Switching the type definition of `RootState` with Redux Toolkit example:
301301

302302
```ts
303-
//instead of defining the reducers in the reducer field of configureStore, combine them here:
303+
// instead of defining the reducers in the reducer field of configureStore, combine them here:
304304
const rootReducer = combineReducers({ counter: counterReducer })
305305

306-
//then set rootReducer as the reducer object of configureStore
306+
// then set rootReducer as the reducer object of configureStore
307307
const store = configureStore({
308308
reducer: rootReducer,
309309
middleware: getDefaultMiddleware =>
@@ -608,7 +608,7 @@ If you need to modify the types of the `thunkApi` parameter, such as supplying t
608608

609609
```ts
610610
const fetchUserById = createAsyncThunk<
611-
//highlight-start
611+
// highlight-start
612612
// Return type of the payload creator
613613
MyData,
614614
// First argument to the payload creator

docs/usage/migrating-to-modern-redux.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ const todosSlice = createSlice({
311311
// `createSlice` automatically generated action creators with these names.
312312
// export them as named exports from this "slice" file
313313
export const { todoAdded, todoToggled } = todosSlice.actions
314-
//highlight-end
314+
// highlight-end
315315

316316
// Export the slice reducer as the default export
317317
export default todosSlice.reducer

0 commit comments

Comments
 (0)