Redux Tutorial #1 - React js tutorial - How Redux Works

LearnCode.academy · Beginner ·🌐 Frontend Engineering ·10y ago
Skills: React80%

Key Takeaways

Explains the basics of Redux for React.js applications

Full Transcript

all right let's learn Redux Redux is great because it changes the flux framework and provides some ways that really help you avoid a lot of complicated bugs that can end up in a flux like application at first this seems really strange because it does a few things very very differently um and they don't seem to be advantages at first but I promise if you have more of a complex application um it's going to be worth the time it takes to set up Redux at first so kind of if you're starting with react and you're just building a small component just use react keep all your data in a state on your maybe layout level component if you're going to be building more of an application use flux flux sets up very quickly and it's really stable in a lot of ways when you start getting into complicated data scenarios complicated chains of events that's when you need to go to Redux because it's really going to simplify your application and the time it takes to set up Redux which is more than flux it's a little more frustrating I'm going to be honest uh but the time it takes to get Redux set up is really going to pay off over the lifespan of the application so let's kind of look at how Redux does things I'm going to take a few minutes just to talk about it in this video and I promise it's going to be time that you save in the long run because if you understand Redux going in it makes it a lot easier to get up to Pace with it so the biggest thing they change is really over here the reducers and the one store we'll start with the one store so you don't have multiple stores with Redux you have one big store and instead of multiple stores you have multiple properties on that one big JavaScript object so whereas in our prior application we would have a to-do list store we would have a settings store and then we'd have maybe a favorites store um in Redux we would just have one big JavaScript object and that's our store and it would have three properties it would have a to-do list property it would have a settings property and it would have a favorites property so it's kind of multiple stores and it behaves like multiple stores but you keep it all in one giant JavaScript object that we never mutate and we never change we never actually change this object we only create new versions of this object that way we always have a full history way back from the time our first our app booted up in the browser to wherever you end up you have a full history of the exact state of your application every step along the way every change along the way and we'll get into that a little bit more but the key thing is the store is immutable you cannot mutate any value on the store you only ever create a brand new store object um so I'll do a video on immutability in JavaScript CU JavaScript really doesn't do immutability natively um it doesn't do it very well anyway so we'll kind of get into immutability in another video if you don't really know what that is so you've got your one store and then you're going to wrap your entire application your entire react application all their components you're going to wrap them with one provider component so if your normal your base uh component is a layout then your base component will be a provider component in Redux that's really the only big change you make to your components um and that that provider component when the store changes it reenders your whole application every single time no matter how many changes there are always renders the whole application which is we've already established react does very well due to Virtual Dom so you've got your provider component listening to the store and then the only thing that changes in the components area is you've got smart components and dumb components and this is really just good react architecture anyway um but you've got these react you've got these smart components and they're the top level like page level some people call them Pages some people call them containers and put them a containers in a containers folder uh but they're smart components they're aware of your framework they know how to pull a property off of your store say the to-dos list piece of that store um and they will take the to-dos list and they'll inject that array of to-dos into all the child properties so you've got your dumb components like your to-do list component and all it knows is give me a list of to-dos it's an array and I'll spit out a to-do list for you I don't care if you're using Redux if you're using flux if you're using relay you give me a list of to-dos and I'm going to spit out a to-do list for you so your smart components again are the only things that are aware of Redux and then they pass they strip the data off of the store and pass it through um and then these components trigger actions and that's the part that's the most like flux they dispatch actions and those actions can dispatch other actions in our flux example um an asynchronous action might dispatch a fetch data action and then when the data comes in from the from the Ajax call it's going to dispatch a receive data action and it's got a payload of all the data or if that errors out it might dispatch a fetch data error action and the payload would be the error message so actions work a lot like flux no real big change there and the reducers is the other big piece that changes so instead of having multiple stores that all manage their own data you have multiple reducers that all modify the a piece of data off of the store but they modify it in an immutable way they always create new chunk of data to go back on the store and we'll cover that again in the immutable video so instead of having those three stores you have three reducers um one reducer will probably work off the to-do list portion of the store one reducer will work off the setting portion of the store and one reducer will work off of the favorites portion of the store the favorites property and what's cool is is they can all react off the same action let's say you're in the settings view over here and you click on the button that says don't show completed or hide completed because it's a to-do list so then we trigger the hide completed action and then all three reducers probably care about that the settings reducer cares because we need to turn hide completed to true so that way that button will toggle in The View on the next render um and then the to-do list reducer cares because we want to now filter out the visible uh we want to set uh visible to false on all the ones that are completed and then on the the favorites view will probably do the same thing all the ones that are completed are also visible false so then all of those act all at once blah blah blah none of them depend on each other because they're not talking to the same pieces of data they simply all make their changes the Store updates the component rerenders the entire application there's no wait for going on uh because they all act on completely different sets of data so that's kind of Redux in a nutshell that's kind of how Redux Works um and some key benefits that Redux really provides is it's a really simplified data because there's one store uh that's pretty much it all your data comes from this one thing there's really most of these racing conditions you would end up with are out of the picture now every of any kind means a complete application rerender and because of that we also get to do time travel history that store is going to keep a complete list of all the store States all throughout time State one state two we made a change we made a change and if at any point in time you want to roll back your application while you're debugging uh you simply say hey let's render this one right here boom and then the provider component can render the application in the exact state it was in there um you can travel back even further let's render this piece of the store State and as long as you did a good job coding and you never changed your actual object but you always created a new one that's going to work flawlessly that's going to work very well so that's Redux in a nutshell that's going to help you understand it a lot more as we get into the code I'm going to go put together an immutability in JavaScript video for those of you guys who don't know what that is and then we'll get into coding Redux

Original Description

This Redux tutorial series will show you the schematics of a Redux application. Redux is AWESOME, but it takes a bit to get it setup. There really aren't a lot of moving parts, but there are a lot of ways that you can configure it - namely - configure the store. Redux is like Flux in several ways, but it's different as well. It has these pieces: - Provider: wraps your application, injecting the store - Store: one large store that contains the state for your entire application - Reducers: reducers listen to actions and make changes on the store values. They also cannot mutate the data on the store in any way, but must return a new set of data. - Actions: pretty much just like flux actions, the only difference is that async can be handled in multiple different ways depending on store "middleware" - Components: React components can be injected with various pieces of store data. React components also trigger Redux actions. This is what makes it all come together. -~-~~-~~~-~~-~- Also watch: "Tailwind CSS - why CSS utility classes save so much time" https://www.youtube.com/watch?v=oU5ar0dmQEY -~-~~-~~~-~~-~-
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from LearnCode.academy · LearnCode.academy · 0 of 60

← Previous Next →
1 Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
LearnCode.academy
2 Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
LearnCode.academy
3 How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
LearnCode.academy
4 Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
LearnCode.academy
5 Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
LearnCode.academy
6 CSS Tutorial - Web Development Tutorial for Beginners (#5)
CSS Tutorial - Web Development Tutorial for Beginners (#5)
LearnCode.academy
7 Node.js tutorial for beginners - an introduction to Node.js with Express.js
Node.js tutorial for beginners - an introduction to Node.js with Express.js
LearnCode.academy
8 Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
LearnCode.academy
9 Javascript Tutorial - Programming Tutorial for Beginners Pt 1
Javascript Tutorial - Programming Tutorial for Beginners Pt 1
LearnCode.academy
10 Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
LearnCode.academy
11 AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
LearnCode.academy
12 WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
LearnCode.academy
13 YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
LearnCode.academy
14 BOWER! - Streamline Web Workflow with Bower Package Manager
BOWER! - Streamline Web Workflow with Bower Package Manager
LearnCode.academy
15 Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
LearnCode.academy
16 GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
LearnCode.academy
17 GITHUB PULL REQUEST, Branching, Merging & Team Workflow
GITHUB PULL REQUEST, Branching, Merging & Team Workflow
LearnCode.academy
18 Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
LearnCode.academy
19 jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
LearnCode.academy
20 jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
LearnCode.academy
21 jQuery Tutorial #1 - jQuery Tutorial for Beginners
jQuery Tutorial #1 - jQuery Tutorial for Beginners
LearnCode.academy
22 Node.js MongoDB Tutorial using Mongoose
Node.js MongoDB Tutorial using Mongoose
LearnCode.academy
23 Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
LearnCode.academy
24 WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
LearnCode.academy
25 jQuery Tutorial #4 - DOM Traversal with jQuery
jQuery Tutorial #4 - DOM Traversal with jQuery
LearnCode.academy
26 jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
LearnCode.academy
27 jQuery Tutorial #6 - Building a jQuery Image Slider
jQuery Tutorial #6 - Building a jQuery Image Slider
LearnCode.academy
28 jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
LearnCode.academy
29 jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
LearnCode.academy
30 jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
31 jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
32 How to put your website online - how to FTP to a domain & upload files to a webhost
How to put your website online - how to FTP to a domain & upload files to a webhost
LearnCode.academy
33 Basic Terminal Usage - Cheat Sheet to make the command line EASY
Basic Terminal Usage - Cheat Sheet to make the command line EASY
LearnCode.academy
34 SSH Tutorial - Basic server administration with SSH
SSH Tutorial - Basic server administration with SSH
LearnCode.academy
35 Vagrant Tutorial - Running a VM For Your Local Development Environment
Vagrant Tutorial - Running a VM For Your Local Development Environment
LearnCode.academy
36 Sublime Text Favorite Packages and Workflow
Sublime Text Favorite Packages and Workflow
LearnCode.academy
37 What Makes Javascript Weird...and AWESOME - Pt 1
What Makes Javascript Weird...and AWESOME - Pt 1
LearnCode.academy
38 Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
LearnCode.academy
39 Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
LearnCode.academy
40 FREE REST API - Practice Developing Javascript AJAX Apps with this API
FREE REST API - Practice Developing Javascript AJAX Apps with this API
LearnCode.academy
41 Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
LearnCode.academy
42 Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
LearnCode.academy
43 Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
LearnCode.academy
44 Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
LearnCode.academy
45 Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
LearnCode.academy
46 Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
LearnCode.academy
47 Web Development Advice - Interview with Dev Tips
Web Development Advice - Interview with Dev Tips
LearnCode.academy
48 How the Internet Works for Developers - Pt 2 - Servers & Scaling
How the Internet Works for Developers - Pt 2 - Servers & Scaling
LearnCode.academy
49 How the Internet Works for Developers - Pt 1 - Overview & Frontend
How the Internet Works for Developers - Pt 1 - Overview & Frontend
LearnCode.academy
50 HAPROXY vs NGINX - 10,000 requests while killing servers
HAPROXY vs NGINX - 10,000 requests while killing servers
LearnCode.academy
51 Node.js Cluster - Boost Node App Performance & Stability with Clustering
Node.js Cluster - Boost Node App Performance & Stability with Clustering
LearnCode.academy
52 Web Dev Training with Treehouse
Web Dev Training with Treehouse
LearnCode.academy
53 What is Node.js Exactly? - a beginners introduction to Nodejs
What is Node.js Exactly? - a beginners introduction to Nodejs
LearnCode.academy
54 How to deploy node.js applications #1 - spin up a server
How to deploy node.js applications #1 - spin up a server
LearnCode.academy
55 Deploying node.js applications #2 - provision server & setup flightplan
Deploying node.js applications #2 - provision server & setup flightplan
LearnCode.academy
56 Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
LearnCode.academy
57 Mobile Web Design - Coding Workflow For Mobile Websites
Mobile Web Design - Coding Workflow For Mobile Websites
LearnCode.academy
58 WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
LearnCode.academy
59 GRUNT TUTORIAL - Grunt makes your web development better!
GRUNT TUTORIAL - Grunt makes your web development better!
LearnCode.academy
60 STOP USING FTP!  - How to Deploy with Flightplan over SSH
STOP USING FTP! - How to Deploy with Flightplan over SSH
LearnCode.academy

Related Reads

Up next
How to Use Semrush Keyword Magic Tool with ChatGPT to Make Money
Grow with Will - SEO, Sales & Entrepreneurship
Watch →