import React, { useCallback, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { CounterReturnType, decrease, increase } from "./redux/CounterReducer";
function App() { const { value } = useSelector((state: CounterReturnType) => ({ value: state.value, }));
const dispatch = useDispatch(); const onClickIncrease = useCallback(() => { dispatch(increase()); }, []);
const onClickDecrease = useCallback(() => { dispatch(decrease()); }, []);
return ( <div className="App"> <div>{value}</div> <button onClick={onClickIncrease}>+1</button> <button onClick={onClickDecrease}>-1</button> </div> ); }
export default App;
|