$chiubaca / notes / fleeting / 2021-05-26
  • Carried on reading some more of A Complete Guide to useEffect (man it’s a long blog!)
    • Thinking about react in effects helps you understand why we might get into unintended re-renders.
    • Every re-renders is an function execution, which folds in values in the current known state. e.g when you run a setTimeout with a variable, then change the variable before the setTimeout has executed, the setTimeout ‘remembers’ the old value still!
    • useState lets you persist state between refreshes/effects. Remember when you update a value with useState this cause a re-renders!
    • useRef lets you mutate values without casing a causing re-renders
    • deps in a useEffect is a way to let React know the exact dependancies the component needs to “watch” for changes to then refresh. But don’t ever lie about deps as a workaround to prevent a refresh. This can cause unintended consequences.
Edit on GitHub ✏️

Hey I'm Alex Chiu 👋. These are my notes for literally anything.

I'm using the Zettelkasten method to organise my thoughts here.

My more polished writings are published to my main blog at chiubaca.com

Follow me on: Github / X (Twitter) / Mastodon / LinkedIn