Questions tagged [redux-thunk]

Thunk middleware for Redux. Redux Thunk middleware allows you to write action creators that return a function instead of an action. The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met. The inner function receives the store methods dispatch and getState() as parameters.

Redux Thunk middleware allows you to write action creators that return a function instead of an action. The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met. The inner function receives the store methods dispatch and getState() as parameters.


Related tags

2622 questions
15
votes
2 answers

Async initial state React-Redux Redux-Thunk

Using React, Redux, Redux-thunk I want to have an initial state through a server request (API call) but I cannot seem to get this to work. What I have got so far: var Redux = require('redux'); var carReducer = require('./reducers/cars'); var thunk =…
Tikkes
  • 4,599
  • 4
  • 36
  • 62
15
votes
1 answer

Initialize component with Async data

I'm trying to figure out how and where to load the data (ie call dispatch on my action) for my select box in react + redux + thunk. I'm not sure if it should go in the constructor of my App container, or should i load it inside my component (in my…
mnsr
  • 12,337
  • 4
  • 53
  • 79
15
votes
1 answer

What are the differences between Redux-Thunk and Redux-Promise when used with Axios apis?

I have been using React , Redux since few months now. One of the most confusing part of the ecosystem is the async data flow. There are many great solutions available and choosing the right solution for your problem is the tough part. In my…
Dishant Soni
  • 153
  • 1
  • 5
15
votes
6 answers

redux action "is not a function" when dispatched from component

I am trying to create an app with a CSV upload. When a CSV is uploaded it will change the state and then I will parse from CSV to JSON and do stuff with it. The idea is to upload a file and update state. Once that state is updated I would pass the…
Brandon Baum
  • 155
  • 1
  • 1
  • 6
15
votes
5 answers

Connect not working with StateLess component in Redux-react

I'm dispatching an action from some-other component , and store is getting updated with svgArr property, but though the following Stateless component connect'ed to the store , it ain't getting updated when store changes for svgArr. Is it how it…
sapy
  • 8,952
  • 7
  • 49
  • 60
14
votes
1 answer

How to return a promise from an action using thunk and useDispatch (react-redux hooks)?

I just started exploring react-redux hooks and I was curious how to return a promise if I am using thunk and useDispatch(). Essentially I want to achieve the following: const dispatch = useDispatch(); dispatch(myAction(...args)).then((result) => { …
Andrew
  • 153
  • 1
  • 1
  • 6
14
votes
4 answers

Typescript Redux Thunk (Types)

I have a redux thunk action that fetches some data and then dispatches some actions (not shown in the code here, but you'll be able to find it in the demo link bellow) export const fetchPosts = (id: string) => (dispatch: Dispatch) => { …
Adrian Florescu
  • 4,454
  • 8
  • 50
  • 74
13
votes
1 answer

Argument of type '(dispatch: Dispatch) => Promise' is not assignable to parameter of type 'AnyAction'

Error: Argument of type '(dispatch: Dispatch) => Promise' is not assignable to parameter of type 'AnyAction'. useEffect(() => { dispatch(GetShops()); }, []); I am trying to implement redux-thunk using Typescript. I have…
Tushar kharat
  • 151
  • 1
  • 1
  • 9
13
votes
3 answers

Typo in static class property declaration react/no-typos

I created a CRUD app using Redux so, I write code and when export the component I added this line: AddContact.PropTypes = { addContact: PropTypes.func.isRequired }; export default connect(null, { addContact })(AddContact); But, It's showing…
Vijay208
  • 167
  • 1
  • 2
  • 10
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…
13
votes
1 answer

type error with redux-thunk when using connect

I am using redux and redux-thunk with typescript. I am trying to inject to a component through connect() a simple thunk action creator, using mapDispatchToProps. Actions export enum TestActionTypes { THUNK_ACTION = "THUNK_ACTION" } export…
vbvx
  • 609
  • 7
  • 22
13
votes
3 answers

How do I handle multiple calls in one thunk function?

I don’t know if everybody has read this: https://medium.com/@stowball/a-dummys-guide-to-redux-and-thunk-in-react-d8904a7005d3?source=linkShare-36723b3116b2-1502668727 but it basically teaches you how to handle one API requests with redux and redux…
Martin Nordström
  • 5,779
  • 11
  • 30
  • 64
13
votes
3 answers

redux-thunk and handling exceptions inside dispatch results

I have a basic thunk action creator and reducer adapted from the Redux documentation: http://redux.js.org/docs/advanced/AsyncActions.html // action creator function fetchPosts () { return dispatch => { dispatch({ type: 'FETCH_POSTS_REQUEST'…
Matt Stone
  • 3,705
  • 4
  • 23
  • 40
13
votes
1 answer

Warning: Failed prop type: The prop `store` is marked as required in `Provider`, but its value is `undefined`. in Provider

How to resolve this error in react-redux project error screenshot Warning: Failed prop type: The prop store is marked as required in Provider, but its value is undefined. in Provider import React from 'react'; import ReactDOM from…
Naveed Aheer
  • 1,715
  • 6
  • 25
  • 40
13
votes
3 answers

Redux Router - "Dispatch is not defined"

I've got a simple component that calls an action when a user loads a page, and inside that action, I'm trying to dispatch another action to set the loggedIn state of the store to true or false: import React, { Component } from 'react' import { Link,…
Mike
  • 2,633
  • 6
  • 31
  • 41