---
title: "Discussion on \"React: Context, Custom hooks and multiple components problem\" | Hashnode"
description: "Discussion on \"React: Context, Custom hooks and multiple components problem\". I had a problem with updating state in my app, which drove me mad. After creating a simplified version in CodeSandbox, and a lot of Googling I eventually figured out the problem.\nThe set up\nMy app contains two components, Button and Text.\nButton cont..."
url: "https://hashnode.com/posts/react-context-custom-hooks-and-multiple-components-problem/60e99b946d962b01bdecc2d2"
---

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

Discussion

# [React: Context, Custom hooks and multiple components problem](https://blog.nicm42.me.uk/react-context-custom-hooks-and-multiple-components-problem?utm_source=hashnode&utm_medium=feed)

I had a problem with updating state in my app, which drove me mad. After creating a simplified version in CodeSandbox, and a lot of Googling I eventually figured out the problem. The set up My app contains two components, Button and Text. Button cont...

Jul 10, 2021 · 2 min read · blog.nicm42.me.uk  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)

## Written by

[Nic](https://hashnode.com/@nicm42)

@nicm42 · England

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

This week I learnt...

Front End Developer. I like problem solving and making things pretty. I also like red.

## Responses 1

Markdown supported · ⌘↵ to post

[Shad Mirza](https://hashnode.com/@iamshadmirza)

[Jul 10, 2021](https://hashnode.com/posts/react-context-custom-hooks-and-multiple-components-problem/60e99b946d962b01bdecc2d2/comment/60e99ee46d962b01bdecc36f)

Context provider "provides" the context to all it's children no matter how deep they are. Since `Button` was outside the provider and not a children of provider, it wasn't able to identify which "context" you're talking when you said `useContext` inside the custom hook.

Always make sure that the component which is using "context" is inside the context "Provider"

[Nic](https://hashnode.com/@nicm42)

[Jul 10, 2021](https://hashnode.com/posts/react-context-custom-hooks-and-multiple-components-problem/60e99b946d962b01bdecc2d2/comment/60e99ee46d962b01bdecc36f#reply-60e99ff5c551f16b0f847be2)

I'm still a bit confused though, because the custom hook isn't inside the context provider. Is it that any component that calls the custom hook must be inside the context provider, if the custom hook uses the context?
