Pablo Garcia
Sep 12, 2023

--

In ReactJS, the effects run when the component first mounts and when the dependencies change. If the effect returns a callback, that callback acts as a cleanup step which runs either when the component is unmounted or just before the next effect kicks in (when the dependencies change). Here, the dependencies array is empty, so the cleanup happens only when the component unmounts.

--

--

Pablo Garcia
Pablo Garcia

Written by Pablo Garcia

Senior Engineer at Netflix, ex-Staff Architect 2 at PayPal. M.S. in Computer Science w/specialization in Computing Systems. B.Eng. in Computer Software.

Responses (1)