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

Dispatching first runs undefined and then resolves in Redux Thunk

I am trying to use Redux thunk to feth data from an API and into redux, but I run into a problem where redux dispatches twice, once with an undefined action, and once with the actual action. i tried changing my action, changing my reducer and my…
0
votes
0 answers

Redux - Async-Await response undefined but 'works'

I'm in the middle of learning redux and I don't understand why response returns undefined. But at the same time when I look in the developer tools -> network I can see that I successfully fetched the data I want. import { onSearchSubmit } from…
Marek B
  • 26
  • 2
0
votes
1 answer

When i am trying to call the api using thunk , i am getting undefined

I am using react with redux tookit to call my api and store my response in the state, but whenever i am calling the async thunk i am getting undefined in response but i am log my response in api, i am getting the expected response, i didn't know as…
0
votes
0 answers

Not beign able to map fetched data from a Redux createAsyncThunk

im using 'create async thunk' this way => import {createAsyncThunk, createSlice} from '@reduxjs/toolkit' import movieApi from '../common/API\'s/movieApi' import { apiKey } from '../common/API\'s/MovieApiKey' import { HTTP_STATUS } from…
Tomas Gil Amoedo
  • 537
  • 3
  • 16
0
votes
1 answer

redux action dispatched successfully but return undefined value

in LisPage.js when component loads its give props.detail undefined after showCardDetail() is called. In logger it is clearly called, but didnt understand why it shows undefined. I tried setTimeout() but still same result. Even that showCardDetail()…
0
votes
1 answer

How to manage redux state when user hits a product details page directly

I am working on a Redux app and I have come across a particular situation that I don't know how to handle. Let's say I have a ProductsList page: example.com/products On this page, I am dispatching the getProducts redux action and it calls the API…
0
votes
1 answer

How to use two different slices with Redux-toolkit?

I'm trying to fetch data from two different API's using Redux-toolkit, however I don't want them to be fetched simultaneously. Let's say I have two buttons and if I click on the button 1 the app should fetch data from the first api and if the click…
Berg_Durden
  • 1,531
  • 4
  • 24
  • 46
0
votes
1 answer

Append Previous State to New State in Redux

I have this app which uses the first createAsyncThunk to get the first page from the API, then I want the second createAsyncThunk, which gets the next page, to fire when the user reaches the bottom of the page and get the data in the infinite…
Nima
  • 996
  • 2
  • 9
  • 37
0
votes
1 answer

Redux thunk function not being executed

I recently started looking at redux thunks. It is my understanding it should be used for dealing with async actions or where there's a need to dispatch actions from within other actions. So I've got my store configured such as: import…
MrCujo
  • 1,218
  • 3
  • 31
  • 56
0
votes
0 answers

React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhausCompiled with warnings

Error while dispatching an action! React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhausCompiled with warnings. App.js :- function App() { const user = null; const…
Ashmita Singh
  • 69
  • 2
  • 2
  • 11
0
votes
1 answer

POST request response undefined , but REQUEST works

userSlice import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; import LoginService from "../../Services/Login.service"; export const userRegister = createAsyncThunk( "users/register", async (params) => { try { const {…
Umut Palabiyik
  • 313
  • 6
  • 16
0
votes
2 answers

Is Redux Thunk Middleware really needed in a React Hooks based App?

In a React App designed using mostly hooks. I don't see the need for the redux-thunk middleware, or am I missing something? Redux-thunk approach const Component = () => { const dispatch = useDispatch() const user = useSelector(state =>…
fseb
  • 105
  • 2
  • 10
0
votes
0 answers

Nextjs redux-thunk wanting to show an alert after dispatch but the alert isn’t seeing the error variable new state

As I mentioned in the title, I want to show an alert showing if the action was successful or not. But when the alert is supposed to show an error it shows success. When I checked the error variable it says undefined but when I checked it by showing…
R4ve
  • 3
  • 4
0
votes
1 answer

Cannot read property 'endsWith' of undefined - Redux Toolkit testing

I'm having issues while testing a slice with React Testing Library. I was running the following simple test: import reducer from "states/slices"; test("should return the initial state", () => { expect(reducer(undefined, {})).toEqual({ …
1 2 3
99
100