Skip to content

Instantly share code, notes, and snippets.

@cecigarcia
Created September 27, 2019 15:20
Show Gist options
  • Save cecigarcia/daa6f7af0d6832e75e93658e1196b90b to your computer and use it in GitHub Desktop.
Save cecigarcia/daa6f7af0d6832e75e93658e1196b90b to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from "react";
const Counter = ({ notify }) => {
const [value, setValue] = useState(0);
useEffect(() => {
notify(value);
}, [value, notify]);
return <button onClick={() => setValue(value + 1)}>Increment</button>;
};
const CounterNotifier = ({ url }) => {
const handleNotify = value => api.send(url, value); // ❌ This way we're redefining the callback on each render
return (
<div>
<p>{`Notifing even values to ${url}`}</p>
<Counter notify={handleNotify} />
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment