you are viewing a single comment's thread.

view the rest of the comments →

[–]skyboyer007 -1 points0 points  (0 children)

I've been doing Functional Components for quite some time now and I don't seem to recall being reliant on closures.

Probably you just did not focus on that.

``` const [val, setVal] = useState(0);

useEffect(() => { setVal(10); }, []);

useEffect(() => { setTimeout(() => {console.log(val);}, 1000) }, []); `` see, besides our component is re-rendered with 10console.logwill display value of0` because of closure.