Skip to content

Commit 86d9737

Browse files
authored
Merge pull request #3030 from LassiKuisma/part-10-fixes
Part 10 fixes
2 parents 195ce9c + df6eacb commit 86d9737

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/content/10/en/part10c.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,14 @@ Note that accessing a context's value using the <em>useContext</em> hook only wo
757757
Accessing the <em>AuthStorage</em> instance with <em>useContext(AuthStorageContext)</em> is quite verbose and reveals the details of the implementation. Let's improve this by implementing a <em>useAuthStorage</em> hook in a <i>useAuthStorage.js</i> file in the <i>hooks</i> directory:
758758

759759
```javascript
760-
import { createContext } from 'react';
761-
import { useContext } from 'react';
762-
763-
const AuthStorageContext = createContext();
760+
import { useContext } from 'react';
761+
import AuthStorageContext from '../contexts/AuthStorageContext';
764762

765-
export const useAuthStorage = () => {
763+
const useAuthStorage = () => {
766764
return useContext(AuthStorageContext);
767765
};
768766

769-
export default AuthStorageContext;
767+
export default useAuthStorage;
770768
```
771769

772770
The hook's implementation is quite simple but it improves the readability and maintainability of the hooks and components using it. We can use the hook to refactor the <em>useSignIn</em> hook like this:
@@ -793,7 +791,7 @@ To learn more about these use cases, read Kent C. Dodds' enlightening article [H
793791

794792
#### Exercise 10.15: storing the access token step2
795793

796-
Improve the <em>useSignIn</em> hook so that it stores the user's access token retrieved from the <i>authenticate</i> mutation. The return value of the hook should not change. The only change you should make to the <em>SignIn</em> component is that you should redirect the user to the reviewed repositories list view after a successful sign in. You can achieve this by using the [useNavigate](https://reactrouter.com/docs/en/v6/api#usenavigate) hook.
794+
Improve the <em>useSignIn</em> hook so that it stores the user's access token retrieved from the <i>authenticate</i> mutation. The return value of the hook should not change. The only change you should make to the <em>SignIn</em> component is that you should redirect the user to the reviewed repositories list view after a successful sign in. You can achieve this by using the [useNavigate](https://reactrouter.com/en/6.14.2/hooks/use-navigate) hook.
797795

798796
After the <i>authenticate</i> mutation has been executed and you have stored the user's access token to the storage, you should reset the Apollo Client's store. This will clear the Apollo Client's cache and re-execute all active queries. You can do this by using the Apollo Client's [resetStore](https://www.apollographql.com/docs/react/api/core/ApolloClient/#ApolloClient.resetStore) method. You can access the Apollo Client in the <em>useSignIn</em> hook using the [useApolloClient](https://www.apollographql.com/docs/react/api/react/hooks/#useapolloclient) hook. Note that the order of the execution is crucial and should be the following:
799797

src/content/10/en/part10d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ As always, test your queries in the Apollo Sandbox first before using them in yo
447447

448448
To learn how to open a URL in a browser, read the Expo's [Linking API documentation](https://docs.expo.dev/versions/latest/sdk/linking/). You will need this feature while implementing the button for opening the repository in GitHub. Hint: [Linking.openURL](https://docs.expo.dev/versions/latest/sdk/linking/#linkingopenurlurl) method will come in handy.
449449

450-
The view should have its own route. It would be a good idea to define the repository's id in the route's path as a path parameter, which you can access by using the [useParams](https://reactrouter.com/docs/en/v6/api#useparams) hook. The user should be able to access the view by pressing a repository in the reviewed repositories list. You can achieve this by for example wrapping the <em>RepositoryItem</em> with a [Pressable](https://reactnative.dev/docs/pressable) component in the <em>RepositoryList</em> component and using <em>navigate</em> function to change the route in an <em>onPress</em> event handler. You can access the <em>navigate</em> function with the [useNavigate](https://reactrouter.com/docs/en/v6/api#usenavigate) hook.
450+
The view should have its own route. It would be a good idea to define the repository's id in the route's path as a path parameter, which you can access by using the [useParams](https://reactrouter.com/en/6.14.2/hooks/use-params) hook. The user should be able to access the view by pressing a repository in the reviewed repositories list. You can achieve this by for example wrapping the <em>RepositoryItem</em> with a [Pressable](https://reactnative.dev/docs/pressable) component in the <em>RepositoryList</em> component and using <em>navigate</em> function to change the route in an <em>onPress</em> event handler. You can access the <em>navigate</em> function with the [useNavigate](https://reactrouter.com/en/6.14.2/hooks/use-navigate) hook.
451451

452452
The final version of the single repository view should look something like this:
453453

0 commit comments

Comments
 (0)