React useEffect stale closure issue

Some time ago I encountered this problem, which might make you scratch your head at first.