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.
The set up
My app contains two components, Button and Text.
Button cont...
blog.nicm42.me.uk2 min read
Shad Mirza
Building Hashnode
Context provider "provides" the context to all it's children no matter how deep they are. Since
Buttonwas outside the provider and not a children of provider, it wasn't able to identify which "context" you're talking when you saiduseContextinside the custom hook.Always make sure that the component which is using "context" is inside the context "Provider"