Redux
import {crateStore} from 'redux'
import {Proveder, useSelector, useDispatch} from 'react-redux';
function reducer(state, action) {
if(action.type === 'up'){
return {...state, calue:state.value + action.step}
}
return state;
}
const initialState = {value: 0}
const store = createStore(reducer, initialState);
const Counter = () => {
const dispatch = useDispatch();
const count =useSelector(state=> state.value);
return <div>
<buttononClick={()=>{
dispatch({type:'up', step:2})
}}>+</button> {count}
</div>
}
export default function App() {
return (
<Provider store={store}>
<div>
<Counter></Counter>
</div>
<Provider>
)
}