Skip to content

Commit ed9242b

Browse files
committed
fix
1 parent a4f03c7 commit ed9242b

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/content/7/en/part7d.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ Expand your solution so that it is again possible to like and delete a blog.
126126
127127
Use the Context API to manage the data for the logged in user.
128128
129-
### Cleanup
130129
131-
#### 7.15: Custom hooks
130+
#### 7.15: Cleaning the code
132131
133132
Your application most likely contains code that handles the logged-in user via <i>localStorage</i> in several places:
134133
@@ -144,12 +143,16 @@ window.localStorage.setItem('loggedBlogappUser', JSON.stringify(user))
144143
window.localStorage.removeItem('loggedBlogappUser')
145144
```
146145
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:
146+
Extract this logic into a dedicated service module <i>src/services/persistentUser.js</i>, that exports the following functions:
148147
149148
```js
150-
const {user, setUser, removeUser} = usePersistentUser()
149+
const getUser = () => { ... }
150+
const saveUser = (user) => { ... }
151+
const removeUser = () => { ... }
151152
```
152153
154+
Replace all direct <i>localStorage</i> access in the application with calls to these functions.
155+
153156
Also take the [useField](/en/part7/more_about_react_hooks) hook introduced earlier in this part into use in the forms.
154157
155158
### More views

0 commit comments

Comments
 (0)