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
0
votes
0 answers

Testing dispatching an action, loading and displaying data on a click (Jest + RTL)

I have a chat application, it has a sidebar with conversations of a user, when one of the conversations is clicked I expect messages from that conversation to be loaded and displayed on the screen (Very similar to Telegram). I recently started…
0
votes
1 answer

Why createAsyncThunk is not returning error message?

The url I put inside axios.get is a wrong url. I am expecting an error message through action.error.message in the reducer section. But it's not returning any message despite the fetch request being failed. The code as follows: usersSlice.js const…
0
votes
1 answer

How to call thunked action creator outside of react component with TypeScript

I have a thunked store created like export const store = createStore, {}, {}>(combinedReducers, applyMiddleware(thunk)); I want to dispatch a thunked action outside of a React component, like…
Michael Tontchev
  • 909
  • 8
  • 23
0
votes
1 answer

Actions must be plain objects. Instead, the actual type was: 'Promise'. ---- already used thunk

I already used thunk middlewares but still getting errors why is that? ------- What am I missing? App.js useEffect(() => { dispatch(getPosts()) }, [dispatch]) Actions file: import * as api from "../api/index" export const getPosts = async…
0
votes
1 answer

Multiple actions from one redux-toolkit thunk

toolkit, and I'm trying to understand exactly how createAsyncThunk fits in all of this. I want to make a call to my server to get session info and the user's info in one call. However, from what I've seen so far on createAsyncThunk, it only uses a…
Brandon-Perry
  • 366
  • 4
  • 18
0
votes
1 answer

How to pass status codes to client side? (Redux asyncThunk)

I want to access the status sent from my Express server in my React component. I am using redux to dispatch a login fetch request and want to conditionally render different childrens based on the status code received (eg. 'Incorrect Password' if…
benwl
  • 366
  • 2
  • 17
0
votes
1 answer

Uncaught TypeError: Cannot read properties of undefined (reading 'stats')

I'm using an API for fetching data and it works just fine, by the way I'm using redux. when I refresh my project. I get this error. I also Have et loading so when data is not fetched, waits for it. I have no clue what to do. This is the component…
Milad.eb96
  • 40
  • 4
0
votes
1 answer

Another React Hook Question - Cannot read properties of undefined (reading 'params')

I really seem to have trouble with react and hooks. I know that the problem could be do to react-dom. I am watching a tutorial that does it with 5 and im using 6. I looked at the documentation, but I honestly can't find the issue. It worked for my…
jpwitt13
  • 57
  • 1
  • 9
0
votes
1 answer

Redux Thunk Dispatch Axios Post Request Body

So I am kinda stuck in trying to send a request body in Redux Thunk using axios. The app I work on has a particular setup, and we have a service which exposes backend methods that we can use in a dispatch call, like so: // action file export const…
Lushmoney
  • 412
  • 11
  • 26
0
votes
1 answer

what is the use of first argument of createAsyncThunk?

I'm new in redux toolkit and I've managed state with redux toolkit lately. But the thing I don't know, what is usage of first argument of CreateAsyncThunk. I've read this article: https://redux-toolkit.js.org/api/createAsyncThunk and according to…
bami
  • 211
  • 1
  • 6
  • 19
0
votes
1 answer

createasyncthunk keeps returning undefined when i create a new user. it works fine without createasyncthunk. I know it's a rookie mistake

const initialState = { user: [], isLoading: false, error: false } export const registerNewUser = createAsyncThunk('register/registerNewUser', async({ rejectWithValue }) => { try { const resp = await…
0
votes
0 answers

Can I make an async call in a redux reducer if don't need the response back?

I know we cannot update the redux state with the response from an async function. But I want to only make an async call and don't require some response back. For example: AsyncStorage.setItem('foo','bar'); in react-native.
0
votes
1 answer

reduxjs/toolkit async Thunk

Hi folks I am new to React just learning reduxjs/toolkit for application state management. I have created simple application for handling posts. Currently what I am doing is loading list of posts using async Thunk called fetchPosts. My async thunk…
Malik
  • 65
  • 2
  • 9
0
votes
2 answers

What is the use of dispatch in redux?

I am trying to follow up Brad Travery tutorial of MERN stack. And he uses dispatch function most of the time when working with redux. Here is userAction.js for instance, import axios from 'axios' import { USER_LOGIN_FAIL, USER_LOGIN_REQUEST,…
Dagmawi
  • 3
  • 3
0
votes
1 answer

Component making two api calls from single dispatch

i have a problem where my component is making two api calls instead of one. I am using react and react-redux with reactjs/toolkit. I tried different solutions like changing dependancy array in useEffect hook, changing request headers, looking…