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"
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?
Shad Mirza
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"