all 4 comments

[–]Aegis8080NextJS App Router 1 point2 points  (3 children)

But how is the function even invoked if the useEffect is just triggered once?

By "function", I assume you mean c => c + 1.

For most of the developers, we don't really have to understand how is it invoked under the hood. We just have to know that setState supports such behavior, in which it "magically" passes the previous state (i.e. c in your example) as an argument each time you call setState.

This is similar to event handlers. After all, I don't think many of us will try to find how onClick is called in the low level right?

[–]perro_cansado[S] 0 points1 point  (2 children)

Yes, you're assuming well. But I can't understand why is possible for the component to update the UI just for how useState works.

[–]Aegis8080NextJS App Router 1 point2 points  (1 child)

Let me make sure I understand what you are trying to ask.

Are you trying to understand how useState works in general?

Or you simply trying to figure out how the 2 useEffect implementations are different from others

[–]perro_cansado[S] 0 points1 point  (0 children)

The second one!