Questions tagged [redux-middleware]

88 questions
13
votes
3 answers

When should I use Redux Saga instead of Redux Thunk, and when should I use Redux Thunk instead of Redux Saga?

The question is different from the past which is why. The question for this one is When. Since both are good frameworks by themselves the question is when should I use thunk than saga. Because one of my friend keeps insisting me to use saga in our…
12
votes
1 answer

Redux middleware async function

I have a redux middleware that interacts with a rest api. I recently started rewriting some fetch functions using async/await. For this to make the most sense for me, I would need the middleware function itself to be an async function so that I can…
11
votes
1 answer

React and Redux: Managing Redux Custom Middleware List

For my react app, I have built many custom middlewares and passed them in the applyMiddleware(). Because I have so many, the redux store file is looking a little congested. Is it a good practice to pass them all in the applyMiddleware() or import…
tim_woods
  • 417
  • 2
  • 16
10
votes
2 answers

Flutter Redux Navigator GlobalKey.currentState returns null

I am developing Flutter with Redux. When a user starts an application, I want Redux to automatically dispatch an action. This action will make the Navigator push different routes dependently. This snippet provided by a Flutter dev member uses the…
Tran Triet
  • 1,257
  • 2
  • 16
  • 34
8
votes
1 answer

Inject middleware after redux store creation

I'm wondering if there is a way to inject a Redux store middleware after the store creation? I'd like to have something like: injectMiddleware(store, [middleware1, middleware2]); In a similar way, we can replace the root reducer on the fly after…
alexmngn
  • 9,107
  • 19
  • 70
  • 130
8
votes
1 answer

Is possible to listen on Redux @@INIT action in middleware

In Redux, there is initial action @@INIT. Is possible to dispatch another action (in middleware) when this action occurred? If not, what is best alternative to push action after store is ready?
Jurosh
  • 6,984
  • 7
  • 40
  • 51
7
votes
2 answers

Custom middleware causes a circular reference in redux

I am trying to convert a redux project to typescript using the provided documentation: https://redux.js.org/usage/usage-with-typescript#type-checking-middleware However I'm having trouble doing it with my custom middleware. Here is the minimized and…
Algirdyz
  • 607
  • 6
  • 16
7
votes
2 answers

How to overcome "A non-serializable value detection"

I'm implementing react app with redux-toolkit, and I get such errors when fetching data from firestore. A non-serializable value was detected in an action, in the path: payload.0.timestamps.registeredAt A non-serializable value was detected in an…
7
votes
2 answers

Jest spyOn() calls the actual function instead of the mocked

I'm testing apiMiddleware that calls its helper function callApi. To prevent the call to actual callApi which will issue the API call, I mocked the function. However, it still gets called. apiMiddleware.js import axios from 'axios'; export const…
Sithideth Bouasavanh
  • 1,011
  • 1
  • 11
  • 20
6
votes
1 answer

Redux for maintaining only shared data

In our Angular app, we are planning to use Redux but decided that we will use it for managing only the data that are shared by at-least two components. The data that are used by only one component will be directly fetched without using Redux. For…
msmani
  • 730
  • 1
  • 7
  • 24
6
votes
2 answers

redux refresh token middleware

I have a middleware that can go to the refresh token before the next action runs and then run the other action when the access token expires. But if I make more than one request at a time and the access token is over, I am trying to get as much…
ccoeder
  • 255
  • 5
  • 20
5
votes
1 answer

"Actions may not have an undefined "type" property. Have you misspelled a constant?"

I'm developing a Facebook app, and I'm using two different modules: AdonisJS and react-redux-starter-kit. I have then an action to store a user that has logged in using Facebook log in button when the callback function is executed: callback = (r) =>…
user4383363
4
votes
1 answer

Typescript: how to type a custom redux middleware that handles async actions

I hope everyone is doing great this weekend! disclaimer: I already researched the whole day and I am coming to ask for help only after I tried many things, I opened more than 20 StackOverflow links and read through them... I have this custom redux…
Wagner Moreira
  • 1,033
  • 1
  • 16
  • 40
4
votes
1 answer

Why Redux middleware defined as three arrow functions instead of a single function with three arguments?

Why do we do this: const middleware = store => next => action => { ... } and not something simpler like const middleware = (store, next, action) => { ... } Was there some advantage to the Redux team for designing middleware this way? Is there some…
Samuel Neff
  • 73,278
  • 17
  • 138
  • 182
4
votes
1 answer

How do I auto-refresh a JWT in redux without breaking async flow?

High-level description I have a React/redux/electron app that uses Google Oauth. I want to be able to refresh the access token automatically when it expires. I've researched this and solved it semi-successfully using middleware, but my solution is…
resistor
  • 173
  • 2
  • 9
1
2 3 4 5 6