Skip to content

Instantly share code, notes, and snippets.

Created Feb 13, 2020
What would you like to do?
React Counter with nested function as side effect dependency [solution 1]
const Logger = ({ index, getCounter }) => {
const [text, setText] = useState("");
// Executa a função para obter o contador
const counter = getCounter();
useEffect(() => {
// usa o contador dentro do callback
const newText = `Contador ${index}: ${counter}`;
}, [
counter // usa o contador como dependência
return <p>{text}</p>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment