Hooks Tips Ep. 2 - Migrating Instance Variables
Published 📅: ....
Last modified 📝: ....
Share this post on BlueskySee discussion on Bluesky
This blog post is part of a series on hooks, this blog post assumes you have a decent initial understanding of React Hooks. I highly suggest starting with the ReactJS Docs to learn more.
Frequently, class based components can have a decent number of instance
variables on them that are unrelated to state or props. These might be used to
store refs for elements, or other data that you may need within the component.
These values are useful to store on the instance because updating them does not trigger a re-render of the component. Here is an example of a class based component that uses a few instance methods (: This is using a non-standard JavaScript syntax to assign the instance variables.):