Skip to content

Commit ac09a39

Browse files
committed
part 7 exercise tweaks
1 parent ba772a1 commit ac09a39

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
*.md
1+
**

src/content/7/en/part7d.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ lang: en
77

88
<div class="content">
99

10-
In addition to the six exercises in the [React Hooks](/en/part7/more_about_react_hooks) sections of this part of the course material, 16 exercises continue our work on the BlogList application that we worked on in parts four and five of the course material. Some of the following exercises are "features" that are independent of one another, meaning that there is no need to finish them in any particular order. You are free to skip over a part of the exercises if you wish to do so. Quite many of them are about applying the advanced state management technique (Zustand, React Query and context) covered in [part 6](/en/part6).
10+
In addition to the six exercises in the [React Hooks](/en/part7/more_about_react_hooks) sections of this part of the course material, 13 exercises continue our work on the BlogList application that we worked on in parts four and five of the course material. Some of the following exercises are "features" that are independent of one another, meaning that there is no need to finish them in any particular order. You are free to skip over a part of the exercises if you wish to do so. Quite many of them are about applying the advanced state management technique (Zustand, React Query and context) covered in [part 6](/en/part6).
1111

1212
If you do not want to use your BlogList application, you are free to use the code from the model solution as a starting point for these exercises.
1313

@@ -21,7 +21,7 @@ One good piece of advice for both refactoring and writing new code is to take <i
2121

2222
<div class="tasks">
2323

24-
### Exercises 7.7.-7.22.
24+
### Exercises 7.7.-7.19.
2525

2626
These exercises assume that you have already completed the exercises [5.24-5.29](/en/part5/react_router_ui_frameworks#exercises-5-24-5-29). If you have not, do those first.
2727

@@ -124,19 +124,45 @@ Expand your solution so that it is again possible to like and delete a blog.
124124
125125
#### 7.14: React Query and Context step 4
126126
127-
Use the useReducer-hook and context to manage the data for the logged in user.
127+
Use the Context API to manage the data for the logged in user.
128128
129-
### Views
129+
### Cleanup
130+
131+
#### 7.15: Custom hooks
132+
133+
Your application most likely contains code that handles the logged-in user via <i>localStorage</i> in several places:
134+
135+
```js
136+
const userJSON = window.localStorage.getItem('loggedBlogappUser')
137+
138+
// ...
139+
140+
window.localStorage.setItem('loggedBlogappUser', JSON.stringify(user))
141+
142+
// ...
143+
144+
window.localStorage.removeItem('loggedBlogappUser')
145+
```
146+
147+
Extract this logic into a custom hook called <i>usePersistentUser</i>. The hook should read the initial value from <i>localStorage</i> on mount and keep the stored value in sync whenever it is updated or cleared. It should be usable like this:
148+
149+
```js
150+
const {user, setUser, removeUser} = usePersistentUser('loggedBlogappUser')
151+
```
152+
153+
Also take the [useField](/en/part7/more_about_react_hooks) hook introduced earlier in this part into use in the forms.
154+
155+
### More views
130156
131157
The rest of the tasks are common to both the Zustand and React Query versions.
132158
133-
#### 7.15: Users view
159+
#### 7.16: Users view
134160
135161
Implement a view to the application that displays all of the basic information related to users:
136162
137163
![browser blogs with users table showing blogs created](../../images/7/41.png)
138164
139-
#### 7.16: Individual User View
165+
#### 7.17: Individual User View
140166
141167
Implement a view for individual users that displays all of the blog posts added by that user:
142168
@@ -171,7 +197,7 @@ const User = () => {
171197
}
172198
```
173199
174-
#### 7.19: Comments, step 1
200+
#### 7.18: Comments, step 1
175201
176202
Implement the functionality for commenting the blog posts:
177203
@@ -183,20 +209,12 @@ In this exercise, it is enough for the frontend to only display the comments tha
183209
184210
An appropriate mechanism for adding comments to a blog post would be an HTTP POST request to the <i>api/blogs/:id/comments</i> endpoint.
185211
186-
#### 7.20: Comments, step 2
212+
#### 7.19: Comments, step 2
187213
188214
Extend your application so that users can add comments to blog posts from the frontend:
189215
190216
![browser showing comments added via frontend](../../images/7/49.png)
191217
192-
#### 7.21: Styles, step 1
193-
194-
Improve the appearance of your application by applying one of the methods shown in the course material.
195-
196-
#### 7.22: Styles, step 2
197-
198-
You can mark this exercise as finished if you use an hour or more for styling your application.
199-
200218
This was the last exercise for this part of the course and it's time to push your code to GitHub and mark all of your finished exercises to the [exercise submission system](https://studies.cs.helsinki.fi/stats/courses/fullstackopen).
201219
202220
</div>

0 commit comments

Comments
 (0)