Timeline for Make React useEffect hook not run on initial render
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 12, 2023 at 21:37 | comment | added | Dima Vishnyakov | Because Booleans are primitives in ES and passed as a values. So useEffect doesn’t know it’s ref. | |
| Jul 7, 2022 at 10:10 | comment | added | Marius Marais | From memory, it'll re-render. That's what ifs are for though :) | |
| Jul 6, 2022 at 8:19 | comment | added | Mario Eis | @RafaelDuarte I don't think it would. As far as I know, React wont trigger re-renders when a Ref updates. It would do, if firstRender would be a state. Am I wrong? Edit: Oh, but possibly it re-renders, when a hook result changes.... | |
| Apr 13, 2022 at 10:54 | comment | added | Rafael Duarte | If you add the firstRender to the array of dependencies in the useEffect, this will run twice (the first time, and when firstRender is set to false) when mounting. I removed it from the dependencies in my code and it worked. | |
| Sep 8, 2020 at 13:45 | history | edited | Marius Marais | CC BY-SA 4.0 | Corrected sentence structure |
| Sep 7, 2020 at 11:21 | review | Late answers | |||
| Sep 7, 2020 at 11:47 | |||||
| Sep 7, 2020 at 10:59 | history | answered | Marius Marais | CC BY-SA 4.0 |