Slide 1

Slide 1 text

Mastering Redux and Redux Toolkit Hope you ready to learn!!

Slide 2

Slide 2 text

Crafted and Taught by: Photo by Pexels - Cliff - Cindy - John Of JS Bits

Slide 3

Slide 3 text

Introduction To Redux Photo by Pexels Redux is a predictable state management library for JavaScript applications. It helps manage the state of an application in a centralized store, making it easier to track changes and maintain a consistent data flow throughout the app. Redux follows a unidirectional data flow pattern and is commonly used with React, though it can be used with other frameworks as well.

Slide 4

Slide 4 text

Photo by Pexels to

Slide 5

Slide 5 text

useState: for Smaller Apps useState is used to add state to functional components. It returns a stateful value and a function to update that value. It allows functional components to have internal state, making them more powerful and capable of handling dynamic data. Photo by Pexels

Slide 6

Slide 6 text

Photo by Pexels Counter using useState: Plain React

Slide 7

Slide 7 text

Photo by Pexels Redux set up in index.js/main.js Root and other reducers Store is ideally the state bank CREATE THE STORE Provide the store throughout the application

Slide 8

Slide 8 text

Photo by Pexels Reducer.js set up Action Creator Reducer updates store/state

Slide 9

Slide 9 text

Photo by Pexels Counter using useSelector And more: Redux

Slide 10

Slide 10 text

React UseState Flow: Photo by Pexels

Slide 11

Slide 11 text

Redux Flow: Photo by Pexels

Slide 12

Slide 12 text

Photo by Pexels Q: What does React do? A: Passes state up then down- which is strenuous State in lower/child components is promote to App.js then passed down Eg BBA to App.js then to A then to AB WHY??!

Slide 13

Slide 13 text

Q:Why Do You Need Redux? A: To Access State EveryWhere Using Store Photo by Pexels Store stores the state and allows any component to access the state. Using the useSelector and

Slide 14

Slide 14 text

Introduction to Redux ToolKit: Redux Toolkit is the official opinionated package from the Redux team that simplifies the usage of Redux and makes the development experience more efficient. It includes utilities to streamline the creation of Redux stores, reducers, actions, and middleware, reducing boilerplate code and making it easier to set up a Redux-based application. Redux Toolkit also promotes writing code in a more "modern" and concise way, encouraging best practices for working with Redux. Considered as a set of tools to make working with Redux more efficient and developer-friendly. Photo by Pexels

Slide 15

Slide 15 text

Comparison Between REDUX and REDUX TOOLKIT Photo by Pexels 1. Boilerplate Code - Redux: Writing Redux code from scratch often involves creating action types, action creators, and separate reducer functions, leading to A LOT OF boilerplate code. - Redux Toolkit: Redux Toolkit significantly reduces boilerplate code by introducing APIs like `createSlice` and `createAsyncThunk`, which automate the creation of actions and reducers, making the codebase more concise and easier to maintain. 2. Complexity - Redux: Vanilla Redux can be complex, especially for developers new to the library, due to its various concepts like actions, reducers, middleware, and the store. - Redux Toolkit: Redux Toolkit simplifies the structure and usage of Redux by providing a more opinionated approach. It combines actions and reducers into "slices," making it easier to grasp the relationships between different parts of the application.

Slide 16

Slide 16 text

Comparison Between REDUX and REDUX TOOLKIT Photo by Pexels 3. Immutable State Updates - Redux: Ensuring immutability in state updates can be challenging and may require additional libraries or boilerplate code. - Redux Toolkit: Redux Toolkit integrates Immer, which allows developers to write mutable update logic for state while automatically handling the immutability under the hood. 4. Middleware and DevTools Integration - Redux: Configuring middleware and integrating DevTools requires manual setup and additional lines of code. - Redux Toolkit: Redux Toolkit comes with built-in support for common middleware and enables DevTools extension integration by default, simplifying the setup process. 5. Selectors - Redux: Writing selectors to extract specific data from the Redux store can become verbose, especially when dealing with complex state structures. - Redux Toolkit: Redux Toolkit's `createSlice` automatically generates selector functions based on defined reducers, reducing the need for manual selector code and making data retrieval more straightforward.

Slide 17

Slide 17 text

Comparison Between REDUX and REDUX TOOLKIT Photo by Pexels 6. Best Practices - Redux: While Redux provides flexibility, developers may follow different patterns and practices, leading to inconsistency across projects. - Redux Toolkit: Redux Toolkit promotes best practices and a standardized way of writing Redux code, leading to more maintainable and scalable applications. 7. Learning Curve - Redux: Learning and mastering the core concepts of Redux can be time-consuming, particularly for newcomers to the library. - Redux Toolkit: Redux Toolkit abstracts away some of the complexities of Redux, making it more accessible to developers, including those with less experience in managing application state.

Slide 18

Slide 18 text

SUMMARY Photo by Pexels ● Redux Toolkit was built on top of Redux to address some of the pain points of working with Redux directly. ● It provides a more streamlined and efficient development experience by reducing boilerplate, integrating commonly used tools, simplifying state updates, and promoting best practices. ● However, it's worth noting that Redux Toolkit is not a replacement for Redux itself; it is just a set of utilities and conventions that enhance the Redux ecosystem. ● Developers can still use traditional Redux if they prefer more control and customization.

Slide 19

Slide 19 text

Q&A ★ Time for questions ★ Clarifying any doubts or queries ★ Interactive discussions- Chip in! Photo by Pexels