Answer the question
In order to leave comments, you need to log in
How to make different states for useContext objects?
Such a question, I have a const :
const [hovered, setHovered] = useState(false);
const toggleHover = () => setHovered(!hovered);
Answer the question
In order to leave comments, you need to log in
Perhaps I misunderstood you, but apparently it's not about setState, and useContext will not help here: you are trying in a boolean variable (which simply contains either "yes" or "no") data on which element hovered by the user.
Not much tinkering with your structure, I can suggest that you create separate states for each child component in your parent component and forward them accordingly.
Although it’s better to learn how to use the useReduce hook (to store all information about hovers in one state)
UPD: I sketched out the code that answers the original question , only the context in it is really superfluous: it would be enough to implement the reducer at the root and forward the wrappers around it with props.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question