DEV Community

Naveen Dinushka
Naveen Dinushka

Posted on

1 1

How to create an action and an action creator in Redux? (Freecodecamp notes)

Notes in QnA format

1) What is one of the core tasks of Redux?
Redux is a state management framework , so updating state is one of its core tasks and state updates are triggered by dispatching actions

2) What is an action in Redux?
An action is simply a JS object that contains information about an action event that has occurred. The Redux store receives these action objects, then updates its state accordingly. Sometimes a Redux action also carries some data. While data is optional, actions must carry a type property that specifies the 'type' of action that occurred.

*3) What's an example of Redux action? *
An action can be Logging in and data carried by that could be Login Username.

4) What does Action creators do and how to create one?
In Redux we need Action creators to accomplish an action , it is simply a JS function that returns an action.

5) Define a function named actionCreator() that returns the action object when called

const action = {
type: 'LOGIN'
}
// Define an action creator here:
const actionCreator=()=>{
return action;
}
view raw redux_3.js hosted with ❤ by GitHub

Knowledge Check

1) What is one of the core tasks of Redux?
2) What is an action in Redux?
3) What's an example of Redux action?
4) What does Action creators do and how to create one?
5) Define a function named actionCreator() that returns the action object when called

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

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. ❤️