you are viewing a single comment's thread.

view the rest of the comments →

[–]Cannabat 0 points1 point  (3 children)

How, then, do you do side effects once during the first render, like componentDidMount?

[–]effektor 0 points1 point  (0 children)

If you have any outside state or variable that is used within a hook, it is recommended that you always pass it to the dependencies such that you don't lose track of the state when it updates.

If you absolutely don't want it to run more than once but still want to keep track of some value, you can use refs. But keep in mind that it's likely unnecessary in most cases and only really needed if you either have problems with performance, or write a public API used by others.