---
title: "Discussion on \"The advanced guide to React Context with hooks.\" | Hashnode"
description: "Discussion on \"The advanced guide to React Context with hooks.\". Practical guide"
url: "https://hashnode.com/posts/the-advanced-guide-to-react-context-with-hooks/6057bf4f63a05a21443f3717"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [The advanced guide to React Context with hooks.](https://codereviewio.hashnode.dev/the-advanced-guide-to-react-context-with-hooks?utm_source=hashnode&utm_medium=feed)

Practical guide

Mar 21, 2021 · 6 min read · codereviewio.hashnode.dev  
Updated Apr 25, 2021  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#state](https://hashnode.com/tag/state)
-   [#react-native](https://hashnode.com/tag/react-native)
-   [#reacthooks](https://hashnode.com/tag/reacthooks)

## Written by

[CodeReviewIo](https://hashnode.com/@codeReviewIo)

@codeReviewIo · Belgium

  
[View profile](https://hashnode.com/@codeReviewIo)

Full-Stack Developer

## Responses 1

Markdown supported · ⌘↵ to post

[Hiep Tran](https://hashnode.com/@tranhiepqna)

[Mar 22, 2021](https://hashnode.com/posts/the-advanced-guide-to-react-context-with-hooks/6057bf4f63a05a21443f3717/comment/6058085163a05a21443f397f)

Hi there, Thank you for your content, I've learned a lot from your post. However, I see you make some mistakes during using auth context. First, you created auth context in `src/auth/AuthContext.ts` but you imported the context from `./auth/Context` instead of `./auth/AuthContext`. The second problem I saw in your code that AuthContext may be undefined, we should use [optional chaining](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining) to avoid `Object is possibly 'undefined'` error.

[CodeReviewIo](https://hashnode.com/@codeReviewIo)

[Mar 22, 2021](https://hashnode.com/posts/the-advanced-guide-to-react-context-with-hooks/6057bf4f63a05a21443f3717/comment/6058085163a05a21443f397f#reply-6058f4305771a2129446a7fb)

Thank you, I have updated it. For context value: this actually should be `defaultValue` not undefined but in this case we have to provide full initial data consider it `initialState`. So, the solution that we provide `undefined` or make all the contextValues optional and then pass `defaultState` I would say in this case it depends to your project.👍 Happy that helps.
