Redux & Redux Toolkit Course
Redux & Redux Toolkit
/
Beginner

Actions

Definition

Plain JavaScript objects that represent an intention to change the state. They are the only way to get data into the store. Actions MUST have a `type` property.

Explain Like I'm New

A message or an instruction. It's a tiny object that says 'Hey, a user just did this!'. It always has a `type` (the name of the event), and optionally has a `payload` (the data attached to the event).

Real World Example

A postal letter. The `type` is the address indicating what department it goes to. The `payload` is the letter inside containing the actual data.

Common Use Cases

  • •Describing events that happen in the app

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What is the ONE required property that every Action object must have?

intermediate

  • Why should Action types usually be written as strings (like `'todos/ADD_TODO'`)?

Flash Cards

Question

Required property?

Click to reveal answer
Answer

The `type` property.

Question

Why strings?

Click to reveal answer
Answer

Because strings are easily serializable. This allows Redux DevTools to record the actions, save them, and replay them perfectly for time-travel debugging.