Pergunta de entrevista da empresa NetRex

Write a counter component that increments every second.

Resposta da entrevista

Sigiloso

17 de set. de 2023

Use a setInterval function within the useEffect hook with an empty dependency array. Apply setState callback to make sure that the up to date value of the counter is used. Return clearInterval from the useEffect hook to ensure the interval is removed on component unmount. Use useRef to save component props between renders to avoid stale closures.