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
30
votes
1 answer

redux-thunk dispatch method fires undefined action

Here is the code I'm playing with import { createStore, applyMiddleware } from 'redux' import thunk from 'redux-thunk' import axios from 'axios' const initialState = { user: {}, requesting: false, err: null } const reducer = (state =…
FullStackForger
  • 1,060
  • 2
  • 12
  • 18
29
votes
6 answers

Cannot set getState type to RootState in createAsyncThunk

I cannot set the return type of getState() to RootState. I'm using typescript and VSCode. I have to set the type to any, which stops IntelliSense on that object. Below is the code that has the problem: export const unsubscribeMeta =…
user10832440
29
votes
2 answers

Redux ToolKit: is it possible to dispatch other actions from the same slice in one action created by createAsyncThunk

I am using redux-toolkit with createAsyncThunk to handle async requests. I have two kinds of async operations: get the data from the API server update the data on the API server export const updateData = createAsyncThunk('data/update', async…
Joji
  • 4,703
  • 7
  • 41
  • 86
27
votes
7 answers

React.default.memo is not a function (React-Native) wrapWithConnect

I get this the error _react.default.memo is not a function and wrapWithConnect. This is a react-native project and it worked fine before I used the connect function to connect my dispatch into my react component: Package Versions: "react":…
phaseTiny
  • 369
  • 1
  • 3
  • 6
27
votes
5 answers

Testing dispatched actions in Redux thunk with Jest

I'm quite new to Jest and admittedly am no expert at testing async code... I have a simple Fetch helper I use: export function fetchHelper(url, opts) { return fetch(url, options) .then((response) => { if (response.ok) { …
DanV
  • 3,193
  • 4
  • 29
  • 43
27
votes
3 answers

Can I dispatch multiple actions without Redux Thunk middleware?

I read that Redux Thunk is the reliable way to manage asynchronous actions/request. There's nothing much about dispatching actions by other actions. How about dispatching synchronous actions? I am not sure of thunk approach's performance issues,…
Rafał Łyczkowski
  • 995
  • 2
  • 11
  • 27
26
votes
2 answers

Argument of type 'ThunkAction' is not assignable to parameter of type 'AnyAction'

I have set up a redux thunk function with typescript like this: export const fetchActivities = (): AppThunk => async dispatch => { dispatch(fetchActivitiesRequest()) try { const res = await fetch("/activities") const body =…
Mike Hawkins
  • 2,144
  • 5
  • 24
  • 42
26
votes
1 answer

Calling one action from another action creator

I'm working on a Redux app in which many filter components can change the nature of a search to be performed. Any time the state of one of those filter components changes, I want to re-run a search action. I can't seem to call the search action from…
duhaime
  • 25,611
  • 17
  • 169
  • 224
25
votes
4 answers

redux-thunk: Property 'type' missing when calling action through store.dispatch()

I have found similar issues online but no solution for when calling a redux-thunk Action through store.dispatch(). I have the following action: export class DBActions { static startDatabase(): ThunkAction, {}, IClientState,…
Shin
  • 678
  • 3
  • 12
  • 22
23
votes
6 answers

Call function after dispatch from redux has finished

All around it but not quite as I have enough of an idea of redux-thunk and of react-router but I am not getting this seemingly simple idea of: Call a change in route programmatically via 's history.push('/') after an action has finished…
KellysOnTop23
  • 1,325
  • 2
  • 15
  • 34
23
votes
2 answers

Can I Have Redux-Saga and Redux-Thunk Working Together?

I was working with redux-saga but I'm with a problem: the redux-auth-wrapper needs the redux-thunk to do the redirects, so I simply added the thunk in my store: import {createStore, compose, applyMiddleware} from 'redux'; import createLogger from…
bugalaws
  • 353
  • 2
  • 5
23
votes
3 answers

Where to put business logic in redux? action or store

i come from Reflux to Redux. in Reflux your business logic is exist only in store but in Redux its seems different..for example in "Redux" i have "async-action" and i implemented it with "redux-thunk" . in one scenario i want to check something in…
hossein derakhshan
  • 771
  • 2
  • 10
  • 23
22
votes
1 answer

How to use axios / AJAX with redux-thunk

Im using axios inside my action. I need to know if this is the right way to do it or not. actions/index.js ==> import axios from 'axios'; import types from './actionTypes' const APY_KEY = '2925805fa0bcb3f3df21bb0451f0358f'; const API_URL =…
STEEL
  • 8,955
  • 9
  • 67
  • 89
20
votes
8 answers

createAsyncThunk: Error: addCase cannot be called with two reducers for the same action type

This error occurred when I connect actions to extraReducers My code is export const fetchCountries = createAsyncThunk( `country`, async (organizationId: string) => { export const saveCountry = createAsyncThunk( `country`, async ({ } =>…
Alexey Nikonov
  • 4,958
  • 5
  • 39
  • 66
19
votes
4 answers

Correct TypeScript Type for thunk dispatch?

I have an asynchronous redux action and so am using the thunk middleware. I have mapStateToProps, mapDispatchToProps and connect functions for a component as follows: const mapStateToProps = (store: IApplicationState) => { return { loading:…
Carl Rippon
  • 4,553
  • 8
  • 49
  • 64