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
61
votes
10 answers

Where to dispatch multiple actions in redux?

I am using redux with connect and redux-thunk middleware and containers. Currently when a user perform an action, example one click on a button, I need to dispatch that action (sync) which will dispatch other few actions (asynch). I am aware…
Radex
  • 7,815
  • 23
  • 54
  • 86
61
votes
4 answers

How to use Redux to refresh JWT token?

Our React Native Redux app uses JWT tokens for authentication. There are many actions that require such tokens and a lot of them are dispatched simultaneously e.g. when app loads. E.g. componentDidMount() { dispath(loadProfile()); …
lanan
  • 2,742
  • 3
  • 22
  • 29
60
votes
7 answers

Use reselect selector with parameters

How do I pass additional parameters to combined selectors? I am trying to • Get data • Filter data • Add custom value to my data set / group data by myValue export const allData = state => state.dataTable export const filterText = state =>…
Michal
  • 4,952
  • 8
  • 30
  • 63
60
votes
3 answers

Should I store function references in Redux store?

I'm trying to build keyboard shortcut support into my React/Redux app in an idiomatic React/Redux way. The way I am planning to do this is to have the following action creator and associated action: registerShortcut(keyCode,…
Sachin Rekhi
  • 621
  • 1
  • 5
  • 6
59
votes
5 answers

How to configure redux-persist with redux-toolkit?

I have configured redux-persist with a traditional react-redux setup like this: onst persistConfig = { key: 'root', storage, whitelist: ['todos'], }; const persistedReducer = persistReducer(persistConfig, reducer); const store =…
Ashik
  • 2,888
  • 8
  • 28
  • 53
59
votes
6 answers

Wipe AsyncStorage in react native

I notice that I am wasting a certain amount of time debugging redux actions that I am persisting to AsyncStorage in react-native thanks to redux-persist. Sometimes I'd just like to wipe AsyncStorage to save some development time and try with fresh…
jsdario
  • 6,477
  • 7
  • 41
  • 75
59
votes
2 answers

Where do I fetch initial data from server in a React Redux app?

I've started learning React / Redux and stumbled on something that is probably a very basic question. Below are snippets from my app with some code removed for simplicity sake. My state is described by an array of sites which is empty by default.…
Eugene
  • 4,197
  • 7
  • 37
  • 54
59
votes
8 answers

Using webpack aliases in mocha tests

I'm developing a web app at work in React/Redux/Webpack and am now starting to integrate testing with Mocha. I followed the instructions for writing tests in the Redux documentation, but now I have run into an issue with my webpack aliases. For…
Danny Delott
  • 6,756
  • 3
  • 33
  • 57
58
votes
3 answers

How to use Redux-Thunk with Redux Toolkit's createSlice?

I have come across Redux Toolkit (RTK) and wanting to implement further functionality it provides. My application dispatches to reducers slices created via the createSlice({}) (see createSlice api docs) This so far works brilliantly. I can easily…
Jcov
  • 2,122
  • 2
  • 21
  • 32
58
votes
2 answers

Is it possible to trigger a Redux action from outside a component?

I'm building a React app and am calling a custom handler library to make calls to our REST API. Within these (non-React) functions, I'd like to trigger Redux actions to update the store with the endpoint response, but can't figure out how to trigger…
TUrwin
  • 755
  • 1
  • 5
  • 9
58
votes
8 answers

Modify state in Redux DevTools Extension

In my application state there are values set as initialState. With the React Developer Tools it's very easy to directly modify some state value. Is anything similar possible in Redux DevTools Extension, i.e. click and insert a new value for a…
Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232
58
votes
5 answers

Set default header for every fetch() request

Is it possible, using the fetch API, to set default headers for every single request? What I want to do is set an Authorization header whenever there is a json web token in the localStorage. My current solution is to set the headers with this…
eRodY
  • 635
  • 1
  • 6
  • 10
58
votes
4 answers

Redux Saga async/await pattern

I'm using async/await throughout my codebase. Because of this my api calls are defined by async functions async function apiFetchFoo { return await apiCall(...); } I would like to call this function from my saga code. It seems like I can not do…
mattnedrich
  • 7,577
  • 9
  • 39
  • 45
58
votes
2 answers

react: why static propTypes

I am looking the redux todomvc codes. What is the static keyword in static propTypes?
BAE
  • 8,550
  • 22
  • 88
  • 171
58
votes
9 answers

CSRF with Django, React+Redux using Axios

This is an educational project, not for production. I wasn't intending to have user logins as part of this. Can I make POST calls to Django with a CSRF token without having user logins? Can I do this without using jQuery? I'm out of my depth here,…
Reed Dunkle
  • 3,408
  • 1
  • 18
  • 29