Questions tagged [redux-middleware]

88 questions
4
votes
2 answers

How to dispatch actions from Redux middleware in correct order

As must of the applications in the world, my React application needs to perform some Ajax calls to an API. I've chosen to use Redux middlewares in order to correctly separate API fetching from my components. The idea is to dispatch REQUEST actions…
KorHosik
  • 1,225
  • 4
  • 14
  • 24
4
votes
0 answers

react-native - check expiration of jwt with redux-thunk middleware before every call to API

For my react-native app I need to make sure that before every fetch request to server the use-case below should be executed -> check the expire date of token that is saved to redux. --> If token is not expired, app keeps going on with requested…
Ali Zeynalov
  • 2,867
  • 8
  • 30
  • 54
4
votes
1 answer

How to use redux-persist with custom middleware

Using redux-persist 5.10.0. It's working perfectly after configuring it using the official documentation: // configureStore.js // all imports here const persistConfig = { key: 'root', storage, whitelist: ['auth'] }; const…
Nick Rameau
  • 1,258
  • 14
  • 23
4
votes
2 answers

redux middleware -> intercept/block/transform?

we're running a SPA. dispatched actions (not components) are auth-based. is it possible to intercept and transform dispatched actions? i.e. dispatch({ type: 'FOO', payload: { some: value } }) function magicMiddleware(action) => decide if…
Anthony Chung
  • 1,467
  • 2
  • 22
  • 44
4
votes
2 answers

How can I add data to the pending action?

I am using Axios, Redux and Redux Promise Middleware. I have the following action creator: return { type: 'FETCH_USERS', payload: axios.get('http://localhost:8080/users', { params: { …
Baz
  • 12,713
  • 38
  • 145
  • 268
4
votes
1 answer

Should you dispatch or call next multiple times inside of a Redux middleware?

I'm curious, I've seen in middlewares, such as redux-promise-middleware where we want a single action to fire off multiple actions (e.g. REQUEST, SUCCESS, FAILURE). However, in the middleware, we're provided the dispatch to be able to dispatch these…
Detuned
  • 3,652
  • 4
  • 27
  • 54
3
votes
1 answer

Redux middleware is being called after reducer

I have created a middleware like this: export default store => next => action => { const res = next(action) console.log("Middleware", action.type) return res } and my store configuration is: import { createBrowserHistory } from…
3
votes
1 answer

Is Redux store middleware an example of the Chain of Responsibility design pattern?

Is Redux store middleware an example of the Chain of Responsibility design pattern? If not, what design pattern does it use?
joshweir
  • 5,427
  • 3
  • 39
  • 59
3
votes
3 answers

store defaultstate with redux observable middleware

I am making a redux observable epic as middleware, and also want to provide a default state to store. At some places I have seen applyMiddleware as third argument to createStore function whereas at some places it is second argument. How can I…
madhur
  • 973
  • 1
  • 14
  • 23
3
votes
2 answers

Redux: Proper way to access state from web service?

I have outlined a few ways to possibly access state from the web service, but I do not know which one is the proper one in a react-redux app, or if the proper one is even listed below. Context: Originally, I had an API.js file which acted as a base…
James A
  • 467
  • 4
  • 12
3
votes
2 answers

redux-storage with redux-saga - not saving

I am trying to use both the redux-storage and redux-saga middleware for redux. Each middleware works great on its own, but when I apply redux-storage with redux-saga, the store does not load the prior state. I am adding the middleware as…
kav
  • 261
  • 1
  • 6
  • 14
2
votes
1 answer

Is it OK to have multiple listener middlewares in the same store?

If I use createListenerMiddleware to create 2 separate middlewares, that handle different responsibilities, is that going to have any significant performance cost over creating a single listener middleware? Are there any undesirable ways they can…
David Mason
  • 2,917
  • 4
  • 30
  • 45
2
votes
2 answers

useEffect hook of react vs redux thunk middleware in redux

use effect hook is used to perform the side effects like network requests in react. redux-thunk middleware is also used to perform the side effects like network requests in react. I'm pretty confused, is there any difference in their real…
Nishant Kumar
  • 691
  • 1
  • 11
  • 31
2
votes
0 answers

Custom Middleware in Redux Toolkit

I have created a Reducer with createSlice and want to reset|modify the state of this slice every time a dispatch matches one of the cases of the reducer. Specifically, I want to have an ErrorSlice (ErrorReducer) which is reset before each request,…
Tobi
  • 363
  • 5
  • 15
2
votes
1 answer

How to apply middleware selectively to reducers?

With reduxjs-toolkit I define my store and middleware something like this: const store = configureStore({ reducer: rootReducer, middleware: [reduxWebsocketMiddleware, adamBrownMiddleware] }); However I only want to apply this middleware to…
blarg
  • 3,773
  • 11
  • 42
  • 71