Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const App = () => (
- <Provider initialState={{ count1: 0, count2: 0 }}>
- <Counter1 />
- <Counter2 />
- </Provider>
- );
- const Counter1 = () => {
- const state = useTrackedState();
- const dispatch = useDispatch();
- const incrementBoth = () => {
- dispatch({ type: 'incrementBoth' });
- };
- return (
- <div>
- <div>Count1: {state.count1}</div>
- <button onClick={incrementBoth}>Increment both</button>
- </div>
- );
- };
- const Counter2 = () => {
- const state = useTrackedState();
- const dispatch = useDispatch();
- const incrementBoth = () => {
- dispatch({ type: 'incrementBoth' });
- };
- return (
- <div>
- <div>Count2: {state.count2}</div>
- <button onClick={incrementBoth}>Increment both</button>
- </div>
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement