Re:Thinking in React Hooks
by andrewstuart on Friday December 13, 2019 @12:29AM
(#21779339)
Ah yes I recall.
The key thing to understand about doing this is to set the state in a context, and do the displaying in another component. There's no point in trying to get the component to re-render when the time value updates. That's the wrong way to program react.
counterTimer is always going to be null where you're checking it for null.
You can't really do it properly without also using useRef to track the value. The reason is that the object returned by useRef is always the same, so it's never stale.