DEV Community

Naveen Dinushka
Naveen Dinushka

Posted on • Edited on

1

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

const store = Redux.createStore(
(state = {login: false}) => state
);
const loginAction = () => {
return {
type: 'LOGIN'
}
};
// Dispatch the action here:
store.dispatch(loginAction())
view raw redux_4.js hosted with ❤ by GitHub

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'
}
};

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️