Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import React, { useState, useEffect } from "react";
  2.  
  3. const Counter = ({ notify }) => {
  4. const [value, setValue] = useState(0);
  5.  
  6. useEffect(() => {
  7. notify(value);
  8. }, [value, notify]);
  9.  
  10. return <button onClick={() => setValue(value + 1)}>Increment</button>;
  11. };
  12.  
  13. const CounterNotifier = ({ url }) => {
  14. const handleNotify = value => api.send(url, value); // ❌ This way we're redefining the callback on each render
  15.  
  16. return (
  17. <div>
  18. <p>{`Notifing even values to ${url}`}</p>
  19. <Counter notify={handleNotify} />
  20. </div>
  21. );
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement