For functional components it is encouraged to use useRef
not just for access to dom elements but also to store some data that you do not want to trigger a rerender for.
For class components, I cannot find much information if using createRef
to store data that you do not want to trigger a rerender for is a good idea or not. I understand that class member variables will work for primitive values but I see here that it might not be a good idea for non primitive values. So if you're storing an object for whatever reason, maybe an object of axios's cancellation tokens for each type of request? (The example is just for illustrative purpose)
Can I have a rule of thumb to always use createRef
to store any data, primitive and non-primitive that I don't want to store in my state?
I have not seen any documentation approving createRef
to store mutable data in this way, is it because there's some pitfalls/performance issues or weird behaviour with hot reloading, etc that I might be missing?