Discover this podcast and so much more

Podcasts are free to enjoy without a subscription. We also offer ebooks, audiobooks, and so much more for just $11.99/month.

Bailing out of re-rendering in useState

Bailing out of re-rendering in useState

FromThe Call Kent Podcast


Bailing out of re-rendering in useState

FromThe Call Kent Podcast

ratings:
Length:
4 minutes
Released:
Nov 5, 2021
Format:
Podcast episode

Description

If useState contains a simple value like string or int, setting a new value that is the same as the existing value will not cause the component to re-render. However, if useState contains an object and I update the state with a new object that contains the exact same values, it will trigger the component to re-render. The React documentation says that is used Object.is to compare values. My 2 objects are identical, so why does the re-render happen?

useState lazy initialization and function updates
Released:
Nov 5, 2021
Format:
Podcast episode

Titles in the series (100)

The Call Kent podcast is a regular podcast where you call in with a question and Kent answers. Call in with your questions right from your web browser with any device at https://kentcdodds.com/call