const INCREMENT = "INCREMENT"; // define a constant for increment action types
const DECREMENT = "DECREMENT"; // define a constant for decrement action types
// define the counter reducer which will increment or decrement the state based on the action it receives
const counterReducer = (state = 0, action) => {
switch (action.type) {
case INCREMENT:
return state + 1;
case DECREMENT:
return state - 1;
default:
return state;
}
};
// define an action creator for incrementing
const incAction = () => {
return {
type: INCREMENT
};
};
// define an action creator for decrementing
const decAction = () => {
return {
type: DECREMENT
};
};
// define the Redux store here, passing in your reducers
const store = Redux.createStore(counterReducer);
Hello Redux Learner
Create a function Creator it will include type and payload object
From Function Creator we will Go to Reducers
Create a reducer for Increment and Decrement
Then Create a Root Reducer which we will send to store
Yes we will create a store Then
Go to Main Index file send the STORE through Provider
for sending in provider we need to subscribe() it cos its not free :)
For Getting the State useSelector() from react-redux
and for Updating State useDispatch() from react-Redux
Lets Go KING
counter with redux