Open l-monninger opened 2 years ago
@CarsonMatz
The hover aspect works and I get all the code to make it do so. I did't update it further to allow the user to customize the behavior but I think I have a good idea of how to do so. I would just create a factory of options like the change of opacity and map them to an input in App.jsx, right?
@CarsonMatz Provide an example of what you're thinking of.
React functional components are able to persist state within a lifecycle by use of closures and context stores. This article should help you get a sense of how that works.
While your instinct to try and move the function declaration outside of the functional component is a good one, we do in fact need closures to maintain state. So, this cannot be done.
What you could do instead is define a factory:
This is a great pattern to get familiar with. Though in use cases as simple as this may be overkill.
There are further two additional questions you should be asking yourself: