Avoiding stale state in React useEffect