Created
September 27, 2019 15:43
-
-
Save cecigarcia/1d6d311ab6fcfff7f16e48405b42aaf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect, useCallback } 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 = useCallback(value => api.send(url, value), [url]); | |
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