mikey
mikey
TTCTheo's Typesafe Cult
Created by mikey on 10/12/2023 in #questions
Component renders but DOM doesn't update until next render
thanks, i'll keep this in mind
13 replies
TTCTheo's Typesafe Cult
Created by mikey on 10/12/2023 in #questions
Component renders but DOM doesn't update until next render
the docs say "By default, Effects run after every render (including the initial one)." can't tell if you are you saying this is false, or if you are suggesting a more helpful mental model of render. https://react.dev/learn/synchronizing-with-effects#recap
13 replies
TTCTheo's Typesafe Cult
Created by mikey on 10/12/2023 in #questions
Component renders but DOM doesn't update until next render
thanks for the response. i've read through the learn react guide front to back + did challenges, but I think it's probably time to do it again. In an effort to simplify the problem, I left out some critical info: a parent's state change is triggering re-render of Component. Then would the useEffect run if myDataRef.current had changed? i understand that state change triggers re-render, and that ref change does not. but i am trying to understand why the re-render happened anyway (which i verified it via debugging) but never ended up in the DOM. maybe my question is more of a "useEffect under the hood" one, and i'm looking into it. my understanding is, useEffect holds its own state for all its dependencies. useEffect doesn't know if a dependency comes from a prop or state or ref - they are simply values.
"If data in the dep array has changed since last re-render, i should run this code" during a rerender
just to clarify, the useEffect function runs AFTER, or as a result of, render. I think your concept of "render" in this sentence is "render + effects", yes? I'm also thinking I encountered weird behavior as a result of bad practices and I shouldn't put too effort into trying to understand it haha
13 replies