Getting Rid of Extra State Variables

Let's clean up the useExpanded.js file by removing extra state variables

We'll cover the following

Using a ref Object

As discussed in the last lesson, I prefer to provide the resetDep via a ref object instead of creating a state variable. This way I’m sure to introduce only important variables as actual state variables.

The solution is similar, it’s only an internal change within our custom hook, useExpanded. How the user consumes resetDep remains the same.

So, here’s the implementation with a ref object:

Get hands-on with 1400+ tech skills courses.