Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. const App = () => (
  2. <Provider initialState={{ count1: 0, count2: 0 }}>
  3. <Counter1 />
  4. <Counter2 />
  5. </Provider>
  6. );
  7. const Counter1 = () => {
  8. const state = useTrackedState();
  9. const dispatch = useDispatch();
  10. const incrementBoth = () => {
  11. dispatch({ type: 'incrementBoth' });
  12. };
  13. return (
  14. <div>
  15. <div>Count1: {state.count1}</div>
  16. <button onClick={incrementBoth}>Increment both</button>
  17. </div>
  18. );
  19. };
  20. const Counter2 = () => {
  21. const state = useTrackedState();
  22. const dispatch = useDispatch();
  23. const incrementBoth = () => {
  24. dispatch({ type: 'incrementBoth' });
  25. };
  26. return (
  27. <div>
  28. <div>Count2: {state.count2}</div>
  29. <button onClick={incrementBoth}>Increment both</button>
  30. </div>
  31. );
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement