DEV Community

Naveen Dinushka
Naveen Dinushka

Posted on • Edited on

Dispatching an Action Event in Redux (notes from Freecodecamp)

Notes in QnA format

1.What is the method used to dispatch (send off do something) actions to the Redux store? How is this done
dispatch, is the method that we use to dispatch actions to the Redux store, we do it by passing the value returned from an action creator and then sends an action back to the store

2. What does an action creator return ?
An action creator returns a type property that specifies the action that has occurred. Then the method dispatches an action object to the Redux store , based on the previous example here https://dev.to/naveenkolambage/how-to-create-an-action-and-an-action-creator-in-redux-freecodecamp-notes-3836 following two lines are equal

store.dispatch(actionCreator());
store.dispatch({ type: 'LOGIN' });

3. How would we run dispatch in the following scenario ?
const store = Redux.createStore(
(state = {login: false}) => state
);

const loginAction = () => {
return {
type: 'LOGIN'
}
};

Answer

Knowledge check
1) What is the method used to dispatch an action?
2) What does an action creator return ?
3) How would we run dispatch in the following?
const store = Redux.createStore(
(state = {login: false}) => state
);

const loginAction = () => {
return {
type: 'LOGIN'
}
};

Top comments (0)