In React, A component will update whenever state is updated regardless of whether the next state is identical to the current state. So all we need to make it happen is call a setState function. Doesn't even need a value.

const useForceUpdate = () => React.useState()[1]

This can be useful when using useRef. Changes to refs won't trigger a component to update. Calling forceUpdate after setting a ref may be the trick you're looking for.

Let's talk some more about JavaScript, React, and software engineering.

I write a newsletter to share my thoughts and the projects I'm working on. I would love for you to join the conversation. You can unsubscribe at any time.

Just Enough Functional Programming Logo
Just Enough Functional Programming

Check out my courses!

Liked the post? You might like my video courses, too. Click the button to view this course or go to Courses for more information.
View on