$chiubaca / notes / fleeting / 2021-06-08
  • continuing to read A complete guide to useEffect.
    • the deps array is a hint for a react component to know everything the components depends on. Things go wrong when you try to hack it into the mental model of lifecycle events. Many times it has been explained, using am empty array is a way of saying ‘only run this once’ e.g ‘onMount’. This is not really correct. Always specify all dependancies!

      “But I only want to run it on mount!”, you’ll say. For now, remember: if you specify deps, all values from inside your component that are used by the effect must be there. Including props, state, functions — anything in your component.

    • bring your functions that you only want triggered once into the the useEffect if you want to avoid declaring it as a dependancy.
    • Decoupling Updates from Actions is taking time to grok…
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