Questions tagged [redux-middleware]
88 questions
2
votes
0 answers
Unable to Access Store and Dispatch from Redux Middleware
I am trying to create a simple Redux middleware in my React Redux Electron app that uses Thunk and connected-react-router.
In myMiddleware.js, we need to access the Redux store and dispatch function to send some actions. However, getState and…

Nyxynyx
- 61,411
- 155
- 482
- 830
2
votes
1 answer
What is the difference between a redux middleware and a redux-observable epic?
I would like to understand when it is appropriate to use a redux middleware over a redux-observable epic (and vice versa).
From the redux middleware documentation
It provides a third-party extension point between dispatching an action, and the…

customcommander
- 17,580
- 5
- 58
- 84
2
votes
1 answer
Where should I store the local state of a Redux middleware?
I’m using Redux to manage the logic of a music player. When it’s playing something and suddenly fails, I want to be able to intercept that action and make the player start again, but only n times, as I don't want to keep automatically retrying…

Daniel
- 683
- 1
- 9
- 20
2
votes
0 answers
Best practice to handle redux + axios API request actions
So my scenario is like this:
I have 2 types of requests: "public" requests which don't require authorization information, and "authorized" requests which do.
For authorized requests, before actually sending every request I must put auth info into…

Thiem Nguyen
- 6,345
- 7
- 30
- 50
2
votes
2 answers
Difference Between a Redux middleware and reducer accepting all actions
In my redux project, I want to check something ( for example network connection ) in every action dispatch. Should I implement using a reducer which accepts all type of actions( without type checking ) as given below
export default (state =…

PranavPinarayi
- 3,037
- 5
- 21
- 32
2
votes
1 answer
The implementation of Redux's applyMiddleware
My question is why middlewareAPI can't use :
const middlewareAPI = {
getState: store.getState,
dispatch: dispatch
}
to replace the definition in the source code as below:
export default function applyMiddleware(...middlewares) {
return…

Jason Xu
- 845
- 8
- 22
2
votes
3 answers
dispatch is not defined on my functions using react and redux
I am trying to use react-redux-loading-bar to show a loading bar during fetching data from API servers, I don't use promise middleware so I decided to use it without, the example says do this
import { showLoading, hideLoading } from…

Saifis
- 2,197
- 1
- 22
- 36
2
votes
1 answer
redux: set initial state along with compose middleware
The normal way to set initial state (that overrides a reducer's own default initial state) while creating a store is to provide a second argument to createStore (how to set initial state in redux). But I've unfortunately cobbled together a tangle of…

Sigfried
- 2,943
- 3
- 31
- 43
2
votes
1 answer
Dispatch action in response to another action
I'm setting up redux in my app, and am starting with log in. So far I've got it working great - user logs in using Google, on success my server returns an access token to the web app that is put into the redux store, and can then be used for future…

Graham
- 4,095
- 4
- 29
- 37
1
vote
1 answer
How to use enhance store within redux middleware?
I am building a React-Redux application and need a middleware function that has access to an enhanced store. I am unable to get the enhanced store to be available in the middleware function. Is this possible, if so…

slaughter98
- 1,759
- 14
- 20
1
vote
1 answer
How to resubmit the request after refreshing the token?
The situation: I send a request to receive some data and receive a response that the token has expired. Next, I have to update the token and resend the request that I sent at the beginning. How to do it using redux-toolkit and middleware?
Middleware…

Draktharon
- 111
- 3
1
vote
1 answer
dispatch async function in custom middleware in redux
I am trying to create a custom middleware which dispatches logout action (async function) based on some condition in redux. As soon as action is dispatched, it throws error RangeError: Maximum call stack size exceeded
store.js:
const handleAction =…

Sujay Prabhu
- 151
- 4
- 14
1
vote
0 answers
Redux Middleware: Make Socket.IO connection only after logged in
I am trying to create my first Redux middleware to handle a persistent Socket.IO connection to a chat server. The Redux app should only create the Socket.IO connection after the user has logged in. store.user.id in the Redux store is not null if the…

Nyxynyx
- 61,411
- 155
- 482
- 830
1
vote
2 answers
Redux middleware refresh token gets called after Axios request in the action creator
I'm creating a redux middleware to refresh the token before any request if the token is expired.
The problem is that after the first call I always get error 400 bad request, but if did another call (It's a pagination requrest) it works fine because…

Ruby
- 2,207
- 12
- 42
- 71
1
vote
0 answers
How can this custom redux error middleware being invoked?
Here is the source code.
import {applyMiddleware, createStore} from 'redux'
const reducer = (state = initialState, action) => {
...
if(action.type === 'E'){
throw new Error("AAAAAAA")
}
return initialState;
}
const error =…

jwkoo
- 2,393
- 5
- 22
- 35