Why You Should Use Redux in 2024

Spanish audio is available in the player settings
Rate this content
Bookmark

I've always avoided trying to do sales pitches for Redux, and tbh most of my time has been spent telling people when they _shouldn't_ use Redux :) But I still see lots of folks asking "_when_ should I use Redux?", and "how does Redux compare to $OTHER_TOOL?". So, I figure it's worth actually doing a talk where I cover the actual benefits and reasons to consider using Redux today.

This talk has been presented at React Summit 2024, check out the latest edition of this React Conference.

FAQ

Redux Toolkit is an official, opinionated, batteries-included toolset for efficient Redux development. It simplifies the process of setting up a Redux store, writing reducers, and includes RTK Query for data fetching, effectively solving many common issues and reducing boilerplate code.

Redux has evolved from being a minimal library requiring a lot of boilerplate code to Redux Toolkit, which simplifies common tasks like creating stores and reducers, and includes features like RTK Query for data fetching. Modern React features like hooks have also been integrated into Redux.

Redux was created to manage client-side state in React applications, providing a predictable state update pattern and solving issues related to keeping state in sync across different parts of an application, as initially addressed by the Flux architecture.

Redux is best suited for managing state that is needed by multiple components, state that needs to persist beyond the lifecycle of a single component, and state where it is beneficial to have a clear history of actions and updates. It is less suitable for managing local component state or form state.

Yes, Redux is still relevant for modern React applications. Although there are many state management tools available, Redux provides a consistent and predictable pattern for managing state, especially in larger applications where state needs to be shared across many components.

The benefits of using Redux today include a consistent architectural pattern, predictable data flow, powerful developer tools like Redux DevTools, wide usage and community support, better update performance compared to React context, and strong TypeScript support.

Yes, Redux can be used with server-side rendering (SSR). You can create a Redux store for each request, dispatch actions to fetch data, and then pass the serialized state to the client for hydration. However, whether to use Redux for SSR depends on the specific needs of your application.

Mark Erickson is a senior front-end engineer at Replay, a maintainer of Redux, and the creator of Redux Toolkit. He is known for his extensive documentation work and his Simpsons avatar.

Some trade-offs of using Redux include the added complexity of dispatching actions and writing reducers, the need to manage immutable updates, and potential overuse of a single store for all application state. However, it provides a predictable state management pattern and powerful developer tools.

While useReducer and useContext can mimic some Redux patterns, they differ in that Redux keeps state outside the React component tree, leading to fewer re-renders and better performance in some scenarios. Redux also offers powerful developer tools not available with useReducer and useContext.

Mark Erikson
Mark Erikson
33 min
14 Jun, 2024

Comments

Sign in or register to post your comment.
  • Jerad Rutnam
    Jerad Rutnam
    WSO2
    Thanks! Great session. This helped to verify some of my previous architectural decision and arguments on when we need redux and when we don't require redux. :)
Video Summary and Transcription
Mark Erickson explains the history, creation, evolution, and benefits of Redux. Redux was designed to make state updates and action history maintenance easy, incorporating functional programming principles. Redux Toolkit was created to simplify Redux usage. Redux is still a valid choice for its consistent pattern and separation of state from UI. The decision to use Redux depends on the specific use case and the need for centralized state management.

1. Introduction to Redux

Short description:

Mark Erickson explains why you should use Redux today. He discusses his role as a senior front-end engineer at Replay, his involvement in Redux maintenance and documentation, and the creation of Redux Toolkit. The talk aims to address the historical context of Redux and its appropriate use.

All right. Good morning. My name is Mark Erickson, and today I'm very excited to talk about why you should use Redux today.

A couple of quick things about myself. I am a senior front-end engineer at Replay where we're building a time-travelling debugger for JavaScript applications. If you haven't seen it, please check it out. It will save you so much time investigating issues and trying to fix your flaky tests. Come by and ask me about it later. Very happy to show it off. I am an answerer of questions. I will answer questions pretty much anywhere there is a text box on the internet. I collect any kind of link that looks even remotely useful. I write extremely long blog posts, and I'm a Redux maintainer. I've done most of our documentation, and I created Redux Toolkit, but most people know me as that guy with the Simpsons avatar. It's become a trademark.

Why are we even having this talk anyway? Well, historically, the Redux team has not actually spent really any time at all trying to encourage people to use Redux. In fact, if anything, we've actually spent most of our time telling people you shouldn't actually use Redux in this situation, and part of that is because Redux has been used in a lot of places it really shouldn't have been. So our goal as maintainers is not like we're trying to win market share. We just want Redux to be a very good tool so that if you choose to use it, it works well for you. But we still see a lot of questions about when does it make sense to use Redux?

2. The History and Purpose of Redux

Short description:

The speaker discusses the audience's familiarity with Redux and the Redux toolkit. They express their intention to explore the history, evolution, trade-offs, and positive reasons for using Redux. The speaker briefly mentions not comparing Redux to other libraries or discussing the Redux toolkit. They then provide a quick history of Redux, starting with the release of React in 2013 and the subsequent introduction of the Flux Architecture by Facebook to address state synchronization issues.

How many of you have ever used Redux in any form at all? Okay. Basically the entire room. Cool. How many of you have ever used the modern Redux toolkit package? Okay. Somewhat fewer hands. That's concerning. And just out of curiosity, how many people here have never used Redux? Okay, like, ten people. All right.

So what am I trying to do today? I am a big believer in understanding the history of tools, why were they created, and what problems were they trying to solve. So we're going to take a quick look at the history of Redux and the circumstances surrounding its creation. We're going to talk about how the ecosystem has evolved over time. We'll talk a bit about some of the trade-offs of using Redux. And I'm going to give some positive reasons why it's worth considering using Redux today. Now we've got a limited time, the clock is already ticking. I'm not going to try to compare Redux versus other libraries. I'm not even going to talk about, like, how awesome Redux toolkit is. I've done talks like that before. You can look them up on your own time.

A quick history of Redux. React came out publicly in 2013. And a year later, Facebook announced this concept called the Flux Architecture. And the issue was that they were having trouble keeping state in sync across different parts of their application. Most famously, the notifications button was showing, like, different values than the rest of the UI. And they were having trouble being able to understand how data got updated. So they came up with a pattern called the Flux Architecture, which used words like stores and dispatchers and action objects. And these might sound familiar. And that's because Redux actually got all these terms from Flux initially. It's, like, the reason they're named actions and not events is because Flux used that name first and we just kept the name from Flux. Now Facebook did not release a full library for Flux. Just a couple utilities.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React Compiler - Understanding Idiomatic React (React Forget)
React Advanced 2023React Advanced 2023
33 min
React Compiler - Understanding Idiomatic React (React Forget)
Top Content
Watch video: React Compiler - Understanding Idiomatic React (React Forget)
Joe Savona
Mofei Zhang
2 authors
The Talk discusses React Forget, a compiler built at Meta that aims to optimize client-side React development. It explores the use of memoization to improve performance and the vision of Forget to automatically determine dependencies at build time. Forget is named with an F-word pun and has the potential to optimize server builds and enable dead code elimination. The team plans to make Forget open-source and is focused on ensuring its quality before release.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
React Query: It’s Time to Break up with your "Global State”!
React Summit Remote Edition 2020React Summit Remote Edition 2020
30 min
React Query: It’s Time to Break up with your "Global State”!
Top Content
Global state management and the challenges of placing server state in global state are discussed. React Query is introduced as a solution for handling asynchronous server state. The Talk demonstrates the process of extracting logic into custom hooks and fixing issues with state and fetching logic. Optimistic updates with mutation are showcased, along with the benefits of using React Query for data fetching and mutations. The future of global state management is discussed, along with user feedback on React Query. The Talk concludes with an invitation to explore React Query for server state management.
Managing React State: 10 Years of Lessons Learned
React Day Berlin 2023React Day Berlin 2023
16 min
Managing React State: 10 Years of Lessons Learned
Top Content
Watch video: Managing React State: 10 Years of Lessons Learned
This Talk focuses on effective React state management and lessons learned over the past 10 years. Key points include separating related state, utilizing UseReducer for protecting state and updating multiple pieces of state simultaneously, avoiding unnecessary state syncing with useEffect, using abstractions like React Query or SWR for fetching data, simplifying state management with custom hooks, and leveraging refs and third-party libraries for managing state. Additional resources and services are also provided for further learning and support.
SolidJS: Why All the Suspense?
JSNation 2023JSNation 2023
28 min
SolidJS: Why All the Suspense?
Top Content
Suspense is a mechanism for orchestrating asynchronous state changes in JavaScript frameworks. It ensures async consistency in UIs and helps avoid trust erosion and inconsistencies. Suspense boundaries are used to hoist data fetching and create consistency zones based on the user interface. They can handle loading states of multiple resources and control state loading in applications. Suspense can be used for transitions, providing a smoother user experience and allowing prioritization of important content.
From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.

Workshops on related topic

Rethinking Server State with React Query
React Summit 2020React Summit 2020
96 min
Rethinking Server State with React Query
Top Content
Featured Workshop
Tanner Linsley
Tanner Linsley
The distinction between server state and client state in our applications might be a new concept for some, but it is very important to understand when delivering a top-notch user experience. Server state comes with unique problems that often sneak into our applications surprise like:
- Sharing Data across apps- Caching & Persistence- Deduping Requests- Background Updates- Managing “Stale” Data- Pagination & Incremental fetching- Memory & Garbage Collection- Optimistic Updates
Traditional “Global State” managers pretend these challenges don’t exist and this ultimately results in developers building their own on-the-fly attempts to mitigate them.
In this workshop, we will build an application that exposes these issues, allows us to understand them better, and finally turn them from challenges into features using a library designed for managing server-state called React Query.
By the end of the workshop, you will have a better understanding of server state, client state, syncing asynchronous data (mouthful, I know), and React Query.
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
React Summit 2023React Summit 2023
139 min
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
Top Content
WorkshopFree
Matteo Frana
Matteo Frana
- React Bricks: why we built it, what it is and how it works- Create a free account- Create a new project with Next.js and Tailwind- Explore the directory structure- Anatomy of a Brick- Create a new Brick (Text-Image)- Add a title and description with RichText visual editing- Add an Image with visual editing- Add Sidebar controls to edit props (padding and image side)- Nesting Bricks using the Repeater component- Create an Image gallery brick- Publish on Netlify or Vercel- Page Types and Custom fields- Access Page meta values- Internationalization- How to reuse content across pages: Stories and Embeds- How to create an E-commerce with Products’ data from an external database and landing pages created visually in React Bricks- Advanced enterprise features: flexible permissions, locked structure, custom visual components