Questions tagged [redux]

Redux is a pattern and library for managing JavaScript application state, using events called "actions". It serves as a centralized store for state that is needed across your entire application, with rules ensuring that the state can only be updated in a predictable fashion. Redux make it easier to understand when, where, why, and how the state in your application is being updated, and how your application logic will behave when those changes occur.

Redux is a pattern and library for managing and updating application state, using events called "actions". It serves as a centralized store for state that needs to be used across your entire application, with rules ensuring that the state can only be updated in a predictable fashion. It is inspired by the architecture.

The patterns and tools provided by Redux make it easier to understand when, where, why, and how the state in your application is being updated, and how your application logic will behave when those changes occur. Redux guides you towards writing code that is predictable and testable, which helps give you confidence that your application will work as expected.

Redux Toolkit is the standard approach for writing Redux logic. It provides utilities to simplify several common Redux use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state at once


Useful Links

Related tags

35457 questions
119
votes
7 answers

How do I fix "Expected to return a value at the end of arrow function" warning?

Everything works fine, but I have this warning Expected to return a value at the end of arrow function array-callback-return. I tried using forEach instead of map, but then doesn't even show. How do I fix this? return…
Rami Chasygov
  • 2,714
  • 7
  • 25
  • 37
118
votes
1 answer

Should you ever use this.setState() when using redux?

Should you ever use this.setState() when using redux? Or should you always be dispatching actions and relying on props?
Martol1ni
  • 4,684
  • 2
  • 29
  • 39
117
votes
8 answers

How do I access store state in React Redux?

I am just making a simple app to learn async with redux. I have gotten everything working, now I just want to display the actual state onto the web-page. Now, how do I actually access the store's state in the render method? Here is my code…
Parkicism
  • 2,415
  • 5
  • 20
  • 21
116
votes
6 answers

What is the best way to deal with a fetch error in react redux?

I have one reducer for Clients, one other for AppToolbar and some others... Now lets say that I created a fetch action to delete client, and if it fails I have code in the Clients reducer which should do some stuff, but also I want to display some…
Dusan Plavak
  • 4,457
  • 4
  • 24
  • 35
113
votes
6 answers

React-Redux: Should all component states be kept in Redux Store

Say I have a simple toggle: When I click the button, the Color component changes between red and blue I might achieve this result by doing something like this. index.js Button: onClick={()=>{dispatch(changeColor())}} Color: this.props.color ? blue…
l2silver
  • 3,283
  • 6
  • 23
  • 28
112
votes
10 answers

Why is a Redux reducer called a reducer?

Whilst learning Redux I've came across Reducers. The documentation states: The reducer is a pure function that takes the previous state and an action, and returns the next state. (previousState, action) => newState. It's called a reducer because…
BugHunterUK
  • 8,346
  • 16
  • 65
  • 121
111
votes
4 answers

How does a redux connected component know when to re-render?

I'm probably missing something very obvious and would like to clear myself. Here's my understanding. In a naive react component, we have states & props. Updating state with setState re-renders the entire component. props are mostly read only and…
Joe Lewis
  • 1,970
  • 2
  • 18
  • 20
111
votes
8 answers

How to show a loading indicator in React Redux app while fetching the data?

I'm new to React/Redux. I use a fetch api middleware in Redux app to process the APIs. It's (redux-api-middleware). I think it's the good way to process async api actions. But I find some cases which can't be resolve by myself. As the homepage…
110
votes
1 answer

Can I mapDispatchToProps without mapStateToProps in Redux?

I am breaking apart Redux' todo example to try to understand it. I read that mapDispatchToProps allows you to map dispatch actions as props, so I thought of rewriting addTodo.js to use mapDispatchToProps instead of calling dispatch(addTodo()). I…
Iggy
  • 5,129
  • 12
  • 53
  • 87
110
votes
4 answers

React: Parent component re-renders all children, even those that haven't changed on state change

I haven't been able to find a clear answer to this, hope this isn't repetitive. I am using React + Redux for a simple chat app. The app is comprised of an InputBar, MessageList, and Container component. The Container (as you might imagine) wraps the…
Nicholas Haley
  • 3,558
  • 3
  • 29
  • 50
110
votes
3 answers

State as array of objects vs object keyed by id

In the chapter on Designing the State Shape, the docs suggest to keep your state in an object keyed by ID: Keep every entity in an object stored with an ID as a key, and use IDs to reference it from other entities, or lists. They go on to…
nickcoxdotme
  • 6,567
  • 9
  • 46
  • 72
110
votes
3 answers

How to get simple dispatch from this.props using connect w/ Redux?

I've got a simple React component that I connect up (mapping a simple array/state over). To keep from referencing the context for store I'd like a way to get "dispatch" directly from props. I've seen others using this approach but don't have access…
Toran Billups
  • 27,111
  • 40
  • 155
  • 268
108
votes
3 answers

What is the use of the ownProps arg in mapStateToProps and mapDispatchToProps?

I see that the mapStateToProps and mapDispatchToProps function which are passed to the connect function in Redux take ownProps as a second argument. [mapStateToProps(state, [ownProps]): stateProps] (Function): [mapDispatchToProps(dispatch,…
therewillbecode
  • 7,090
  • 4
  • 35
  • 42
103
votes
11 answers

When would bindActionCreators be used in react/redux?

Redux docs for bindActionCreators states that: The only use case for bindActionCreators is when you want to pass some action creators down to a component that isn't aware of Redux, and you don't want to pass dispatch or the Redux store to it. What…
d.code
  • 1,033
  • 2
  • 8
  • 4
103
votes
11 answers

React/Redux - dispatch action on app load/init

I have token authentication from a server, so when my Redux app is loaded initially I need make a request to this server to check whether user is authenticated or not, and if yes I should get token. I have found that using Redux core INIT actions is…
Shota
  • 6,910
  • 9
  • 37
  • 67