Complete React Tutorial (& Redux) #36 - Redux Actions
Key Takeaways
Shows how to create a Redux action and dispatch it
Full Transcript
all right then so we have at the minute our store created right here and we pass in our reducer so the store knows which reducer is going to interact with it and the reducer is just a function it takes in the state which represents the state of the store and an initial value which is the initial state of the application and also an action right here so remember if we want to edit the data in the store we don't edit it directly we go through a process we first have to dispatch an action into the reducer so it takes the action then down here we look at that action and change the state on the store based on the action and remember we have access to the state so this is where we can update it okay so let's go ahead and create an action so an action is just a JavaScript object and it has a type property and that describes the action and it also has an optional payload of data so for example let's create a new action here we'll store this in a constant and we'll call it Todo action so the idea here is that we're going to add a new to-do using an action so we'll set this equal to a JavaScript object that's what an action is and it has a type property now normally you see the type in capital letters and it's descriptive so I'm going to call this adore to do like so so that describes the type of this action what is it meant to do we want to add a Todo so that's what it does right there that's the thing that describes the action then we have an optional load of data if we want to and we can call this whatever you want I'm going to call it to do since that's what we're adding and I'll just pass as the value to this a string which is by milk okay so what we're doing here is creating an action which we're going to pass into this thing right here we're going to dispatch it and that basically means we're passing it into the reducer the reducer can therefore take that action can see that it's an add to-do so it knows that we want to add a to-do now to the state and we know the to-do it needs to add okay so this is the process now we've created the action here but we're not doing anything with it yet we need to actually dispatch the action so the way we dispatch an action is to take our store that we've already created first of all so let's do that and then use a method called dispatch like so now in here we the actual action that we want to dispatch so I could pass in here the Todo action like so okay that we've just created so I'm saying I want to dispatch this to-do action which means send it to the reducer therefore this function is going to run we have access to the action now which is just this thing that we passed in and we can do something with it so for now let us just console.log the actual action that we receive and we'll console the log the state which is this thing that we're taking in and remember initially it's this all right okay so if we try to run this now what do you think will happen well the console is over here on the left I'm going to save this first of all then I'm going to run it and just watch what happens on the left over here we get this logged first time round so that's the first time the reduce actually runs when we create the store and pass this function into it so it runs once before we even dispatch any action right and we get that object right here of the state because we're logging it to the console so the second time it runs is when we dispatch this action and you can see down here we get that object and the state is still the same because we've not edited that but we also get this thing right here which is the action we get the to-do which is buy milk and the type which is ADD Todo all right so typically what we could do is use a dispatch from a component to update the state that's going to go to the reducer and do something with the action and maybe manipulate the state so now we know how to dispatch actions let's in the next video come inside this function and actually change the state of our store to update it
Original Description
In this React & Redux tutorial I'll show you how to create a Redux action and dispatch it. The reducer will take the action as a parameter.
----------------------------------------
🐱💻 Course Links:
+ VS Code editor - https://code.visualstudio.com/
+ GitHub repository (course files) - https://github.com/iamshaunjp/react-redux-complete-playlist
+ React CDN - https://reactjs.org/docs/cdn-links.html
----------------------------------------
🤑 Donate @ https://www.paypal.me/thenetninja
🎓Find me on Udemy @ https://www.udemy.com/user/47fd83f6-5e4a-4e87-a0f0-519ac51f91b6/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
Related AI Lessons
⚡
⚡
⚡
⚡
Next.js vs Remix vs SvelteKit: Which Framework Should You Learn?
Dev.to · Etrit Neziri
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
🎓
Tutor Explanation
DeepCamp AI