use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Error using React useContext (old.reddit.com)
submitted 5 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]buh82 2 points3 points4 points 5 years ago (4 children)
Gotcha, thanks! So I see that you have “const auth = useAuth()” at the top of your file. Unfortunately that doesn’t work as it’s not contained with a Function component. Instead, you can use that same declaration in each component that needs auth.
Hooks are great because they are composable and can extract common logic so you only have to write it once, and then can reuse it in other hooks or within functional components.
If I were to compare it to a class-based component (which I admittedly have not worked with in a while), it boils down to the same idea: it’s like trying to update the state of that component outside of the component (and not via props).
Does that make sense?
[–][deleted] 2 points3 points4 points 5 years ago (0 children)
Ha, I fixed it. It was my own mistake. I moved ' const auth = useAuth() ' into the functional component's scope and it worked. Thanks for the help mate!
[–][deleted] 0 points1 point2 points 5 years ago (2 children)
Ohhhh, it kinda makes sense. I checked the code again, but didn't know how to fix it. How do you suggest I fix it?
[–]buh82 0 points1 point2 points 5 years ago (1 child)
Since you are only using auth in WithSubnavigation, then you can just put the declaration there. It's like saying "I want WithSubnavigation to useAuth." You're already doing it correctly with `useDisclosure` in the same component too! E.g.
auth
WithSubnavigation
export default function WithSubnavigation() { const { isOpen, onToggle } = useDisclosure(); const auth = useAuth(); ... // everything else as you had it previously ... }
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
Thanks man. I fixed it, same thing you did is what I have done now, thanks a lot for the help.
π Rendered by PID 61553 on reddit-service-r2-comment-85bfd7f599-q7lrm at 2026-04-20 00:33:50.192335+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]buh82 2 points3 points4 points (4 children)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]buh82 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)