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
103
votes
3 answers

What is the difference between redux-thunk and redux-promise?

As far as I know and correct me if I am wrong, redux-thunk is a middleware which helps us dispatch async function and debug values in the action itself while when I used redux-promise I couldn't create async functions without implementing my own…
shet_tayyy
  • 5,366
  • 11
  • 44
  • 82
100
votes
9 answers

How to access state inside Redux reducer?

I have a reducer, and in order to calculate the new state I need data from the action and also data from a part of the state not managed by this reducer. Specifically, in the reducer I will show below, I need access to the…
kibowki
  • 4,206
  • 16
  • 48
  • 74
98
votes
8 answers

useDispatch() Error: Could not find react-redux context value; please ensure the component is wrapped in a

I am trygin to use React-Redux library and I am getting the error on the title. I wrapped my components with Provider but I still get the error, only if I implement the useDispatch() hook. The app worked fine, until I added the useDispatch() line.…
MIPB
  • 1,770
  • 2
  • 12
  • 21
96
votes
2 answers

Isn't Redux just glorified global state?

So I started learning React a week ago and I inevitably got to the problem of state and how components are supposed to communicate with the rest of the app. I searched around and Redux seems to be the flavor of the month. I read through all the…
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
95
votes
6 answers

What are differences between redux, react-redux, redux-thunk?

I am using React + Flux. Our team is planning to move from flux to redux. Redux is very confusing for me coming from flux world. In flux control flow is simple from Components -> actions -> Store and store updates back components. Its simple and…
Chetan Motamarri
  • 1,204
  • 2
  • 12
  • 15
95
votes
6 answers

How to sync Redux state and url query params

I have a web page with a search panel. Search panel has several input fields: id, size, ... What I want is when user set search values (for example: id=123 and size=45) and press a search button: searchState in Redux reducer should be updated with…
95
votes
4 answers

React with Redux? What about the 'context' issue?

I normally post code related stuff on Stack, but this is more a question about what the general thoughts of the community are. There seems to be a lot of people advocating the use Redux with React to manage data/state, but while reading and learning…
Stephen Last
  • 5,491
  • 9
  • 44
  • 85
94
votes
7 answers

Jest setup "SyntaxError: Unexpected token export"

I'm implementing tests into an existing project that currently has no tests. My tests are failing to compile node_modules/ imports. /Users/me/myproject/node_modules/lodash-es/lodash.js:10 export { default as add } from…
Cory Robinson
  • 4,616
  • 4
  • 36
  • 53
94
votes
3 answers

getState in redux-saga?

I have a store with a list of items. When my app first loads, I need to deserialize the items, as in create some in-memory objects based on the items. The items are stored in my redux store and handled by an itemsReducer. I'm trying to use…
Andy Ray
  • 30,372
  • 14
  • 101
  • 138
93
votes
10 answers

How to test a component using react-redux hooks with Enzyme?

I have a simple Todo component that utilizes react-redux hooks that I'm testing using enzyme but I'm getting either an error or an empty object with a shallow render as noted below. What is the correct way to test components using hooks from…
crowns4days
  • 963
  • 1
  • 6
  • 6
93
votes
4 answers

Subscribe to single property change in store in Redux

In Redux I can easily subscribe to store changes with store.subscribe(() => my handler goes here) But what if my store is full of different objects and in a particular place in my app I want to subscribe to changes made only in a specific object in…
Rocky Balboa
  • 1,456
  • 2
  • 13
  • 21
93
votes
11 answers

Why are Redux's state functions called reducers?

This is a part the official Redux documentation: It’s called a reducer because it’s the type of function you would pass to Array.prototype.reduce(reducer, ?initialValue) It doesn't make much sense to me. Could somebody explain to me why they are…
Anton Savchenko
  • 1,210
  • 1
  • 8
  • 11
91
votes
11 answers

Why do I get “Reducer [...] returned undefined during initialization” despite providing initialState to createStore()?

I had set InitialState in my redux createStore method ,and I corresponding InitialState as second arguments I got a error in browser: Uncaught Error: Reducer "postsBySubreddit" returned undefined during initialization. If the state passed to…
Ice Wilder
  • 941
  • 1
  • 7
  • 7
90
votes
6 answers

Avoid no-shadow eslint error with mapDispatchToProps

I have the following component that triggers a no-shadow ESlint error on the FilterButton props. import { setFilter } from '../actions/filter'; function FilterButton({ setFilter }) { return (
Kerumen
  • 4,193
  • 2
  • 19
  • 33
87
votes
4 answers

Passing props to react-redux container component

I have a react-redux container component that is created within a React Native Navigator component. I want to be able to pass the navigator as a prop to this container component so that after a button is pressed inside its presentational component,…
Mike
  • 6,149
  • 5
  • 34
  • 45