help with react context
Im making a tooltip that is on the topmost part of the document, and it needs to know if a component is being hovered, that component is nested.
TooltipContext file
9 Replies
Being used in home.jsx
but there is this error at useTooltip() being undefined
TypeError: Cannot destructure property 'tooltip' of 'useTooltip(...)' as it is undefined.
at Home (Home.jsx:16:11)
is there a way to use a usecontxt inside my csstransition in={}?
Sorry I don't know exactly, but possibly the tooltip useState is initializing with the wrong object shape - maybe try using an object with top, height, left when initializing the position property in the default useState.
oh ok
so dont use null
i think im not allowed to use useContext if its not inside of the provider
I also see the provider value object is wrapped with double brackets, can't remember if that's always right or not.
Sometimes the shape of the initial object needs to match exactly, or expected properties don't exist when first loaded
Or could be that too, but you had a custom hook so I guessed you knew a trick lol
the custom hook just wrapped the useContext
ill try moving the stuff inside of tooltipProvider into another component
That error is usually clear though, I think it says that context can only be used within the provider wrapped components.
I fixed it
what worked?
i put <css transition><toltip><css> in another component, then i was able to use my usecontext hook