Skip to content

[Tutorial Docs] Updating Initial state to account for expected changes in UI #3964

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/tutorials/essentials/part-4-using-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,40 @@ export const ReactionButtons = ({ post }) => {

Now, every time we click a reaction button, the counter should increment. If we browse around to different parts of the app, we should see the correct counter values displayed any time we look at this post, even if we click a reaction button in the `<PostsList>` and then look at the post by itself on the `<SinglePostPage>`.

Whenever adding new properties to state or state objects, it is important to make sure to also update initial state if there are any defuault objects. Just like before when we added user and date to our initial state of posts, we also need to add 'initial reactions' as well.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Whenever adding new properties to state or state objects, it is important to make sure to also update initial state if there are any defuault objects. Just like before when we added user and date to our initial state of posts, we also need to add 'initial reactions' as well.
Whenever adding new properties to state or state objects, it is important to make sure to also update initial state if there are any default objects. Just like before when we added user and date to our initial state of posts, we also need to add 'initial reactions' as well.

Corrects a spelling error


```jsx title="features/posts/postsSlice.js"
import { createSlice, nanoid } from '@reduxjs/toolkit'
// highlight-next-line
import { sub } from 'date-fns'
const initialState = [
{
// omitted fields
content: 'Hello!',
// highlight-next-line
reactions: {
thumbsUp: 0,
hooray: 0,
heart: 0,
rocket: 0,
eyes: 0
}
},
{
// omitted fields
content: 'More text',
// highlight-next-line
reactions: {
thumbsUp: 0,
hooray: 0,
heart: 0,
rocket: 0,
eyes: 0
}
}
]
```

## What You've Learned

Here's what our app looks like after all these changes:
Expand Down