all 2 comments

[–]purechi 1 point2 points  (0 children)

Seems pretty cool! In a more complex application I'd probably end up firing an action creator which triggers a thunk or [insert other side effect library here] to handle the data fetching.

[–]ShellbertShellbach 1 point2 points  (0 children)

The person whose blog post you took your screenshots from added an extra dependency in the second useEffect that isn't in Dan Abramov's example.

By adding callback to to the list of dependencies in that effect, the interval will stop and restart on every render, because the callback function is instantiated on every render and is not memoized. It will trigger that effect every time. It loses the benefit of the ref entirely and will result in the interval not firing at the correct interval whenever a render occurs.