181 questions
1
vote
1
answer
500
views
I am getting an error while trying to import 'thunk' from 'redux-thunk' [duplicate]
I am new to React and Redux, and I am trying to build a webapp (authentication system) using React and Django.
I am following a tutorial to do that, with this github directory.
When I try to import ...
0
votes
0
answers
34
views
fetching data in redux using Axios Get
The endpoint is http://127.0.0.1:8000/api and I can see the data if I go to that endpoint in my browser.
amazonslice.js
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
...
-1
votes
1
answer
107
views
dispatch(fetchPosts()) give empty state
Here is all ok, response.data is array:
export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => {
const response = await axios.get('https://640114a00a2a1afebee5c77d.mockapi.io/...
-1
votes
1
answer
241
views
Then works but await doesn't work with Promise from thunk action
I'm using redux/toolkit and have a thunk action to request an update API then do navigation.
I try to return a promise so that I can wait for the operation to complete before navigation.
The issue ...
0
votes
2
answers
811
views
Return Promise response from Async Thunk
I have a an Axios promise being called from an asyncThunk. I am using the redux toolkit to capture the responses. However, I do not know of a way to return the actual response of the promise call to ...
0
votes
1
answer
455
views
Problem with redux-toolkit (createAsyncThunk) in react native expo app
My problem is on redux-toolkit on a react-native application with Expo.
To put you in the context I am quite a beginner.
Here is my code :
export const fetchStationsInformations = createAsyncThunk(
&...
1
vote
1
answer
219
views
Please explain coding for "thunks."
I have the following code I've tried from the book.
;pg 51 "The Scheme Programming Language" by R. Kent Dybvig"
(define lazy
(lambda (t)
;so lazy accepts argument t
(...
1
vote
1
answer
49
views
How does action creator which is a thunk receive a store's dispatch method?
I am learning redux and there is one thing puzzling me regarding the internal logic - how does a thunk receive dispatch as argument if a thunk is an argument to dispatch and not vice versa? Here is a ...
0
votes
1
answer
46
views
Wait for API fetch to complete before defining const in Redux
I'm attempting to render a page of Pokemon with their attributes (when selected) in react-redux.
I have a PokemonDetail component
export function pokemonDetail (props) {
const { id } = useParams()
...
0
votes
1
answer
52
views
useEffect / dispatch multiple network calls
useEffect(() => {
function initDashboardData() {
console.count("initDashboardData");
void dispatch(getDatabasesList());
void dispatch(getUserConfig());
void ...
0
votes
1
answer
39
views
calling another function in another action
import Axios from "axios";
export const ChangeTodoCount = (newCount) => {
return {
type: "CHANGE_TODO_COUNT",
payload: newCount,
};
};
export const FetchToDo = () =...
1
vote
0
answers
920
views
SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON when Fetching Data
I am trying to fetch some data for my project, using Redux Thunk but i get the error which appears in the screenshot.
This is the error](https://i.sstatic.net/6Dqtm.png)
My thunk function
`
export ...
-1
votes
1
answer
987
views
Receiving 404 Error from Axios post request to MongoDB
I am working on a MERN stack project for a proof-of-concept and am creating a wall where I can add posts from a form. The form accepts name, tags, title, and a message along with an image. Upon ...
-1
votes
1
answer
419
views
can you clarify the use of thunks in redux toolkit? a few specific questions [closed]
Looks like thunk and saga are 2 types of middleware to allow side effects and asyncronous actions in Redux Toolkit. Based on some basic googling, looks like thunk and saga basically serve the same ...
0
votes
1
answer
19
views
How to retrieve data after successful redux dispatch inside a SignIn form component
I have a SignIn form. When the login and pass submitted I am using dispatch to send data and get the JWT token.
Form code:
import React from 'react';
import Avatar from '@mui/material/Avatar';
import ...
0
votes
1
answer
74
views
Api for orderplace is not found in redux
My /api/orders is not getting found.
I had the same approach for users and products and they worked. I am following BradTraversy's Mern Ecommerce from scratch.
This is his github repo but this is ...
0
votes
1
answer
199
views
How to provide mock implementation to redux thunks?
How can we mock implementation for redux thunks.
I have thunks in a file:- src/actions.js
export const getRequest = () => async dispatch => {
return await dispatch(
...
1
vote
0
answers
115
views
Status of Async-Thunk not updating, causing multiple api calls
I am trying to define an Async Thunk method that calls a basic async function and returns the data. I am going to subsequently use this data in multiple components.
I cannot achieve this without the ...
0
votes
1
answer
326
views
Uncaught TypeError: Cannot read properties of undefined (reading 'then')?
saveProfile() does not return promise, although the person who has exactly the same code, the same function returns promise
return async (dispatch, getState) => {
const authUserId = getState()...
1
vote
1
answer
325
views
Redux-Thunk Error: Actions must be plain objects. Use custom middleware for async actions
I have a songbook app with firebase as a backend and struggling with an
Error: Actions must be plain objects. Use custom middleware for async actions.
Action creator
export const createAction = (type, ...
0
votes
1
answer
318
views
Catch the errors from the thunk into the functional components React
How can I catch the errors from async method in the thunk into the Functional Components?
For example I have the following thunk:
export const updateCostCenter = (data: Record<string, unknown>) =...
2
votes
1
answer
31
views
Can a getter return a thunk or value depending on the type call call (virt. property or function)?
I know this a weird question, but I'll ask it anyway.
The pseudo code function below provides a virtual property getter. What it should do is this:
> const calc = Calculator(3)
> calc.multiple ...
1
vote
1
answer
2k
views
Getting some kind of error in react redux with typescript while trying to dispatch a thunk action in a component
So hi guys, this is my first project where I try to use react-typescript with redux-toolkit and am getting an error:
Argument of type 'AppThunk' is not assignable to parameter of type 'AnyAction'. ...
1
vote
1
answer
2k
views
Jest: How to mock redux-thunk api response?
I am having hard time to mock api response in my thunk. Mock returns data undefined.
Error: expect(jest.fn()).toHaveBeenCalledWith(...expected)
Expected: {"payload": {"data": [&...
0
votes
1
answer
849
views
Actions must be plain objects. Use custom middleware for async actions error eventhough useing thunk as middleWare
I got this error:
"Actions must be plain objects. Use custom middleware for async actions."
even though i use thunk as a middleWare.
import { createStore, applyMiddleware } from 'redux';
...
5
votes
2
answers
12k
views
How to get updated state from Redux store using redux-toolkit after component has already rendered?
The functionality I am looking for is that of an e-commerce website. A click on the add-to-cart button adds product to cart. I am able to successfully achieve that by dispatching an action.
Post that ...
0
votes
0
answers
127
views
Test async thunk with jest mock
Maybe someone can help me write test?
This theme is difficult for me, i'll hope somebody explain that.
return axios.post("http://localhost:5000/login", {
login,
password,
});
};
...
1
vote
2
answers
1k
views
useSelector cannot make real time update once the state is changed in react [duplicate]
I'm implementing a search functionality by using react and redux thunk. The requirement for this search is to get fetchApi called in the thunk and update the state so we can display. The ui part is ...
0
votes
1
answer
486
views
Dispatch form data to thunk results in 'breaking the rules of hooks' error
This is a simple task, but I'm doing something wrong and don't know how to do it right. Help is appreciated.
All I need to do is dispatch some form data to a thunk. The thunk has useSelector() in it, ...
1
vote
2
answers
754
views
Typing dispatch on a redux store correctly when using multiple middleware
I'm attempting to configure the dispatch type on a redux store that is using thunk middleware and an optional middleware logger (redux-logger).
This correctly infers the thunk type on store's dispatch....
0
votes
1
answer
1k
views
redux thunk wait data from a dispatch before to do an another dispatch
I'm trying to improve my code by trying to use redux thunk as well as possible but I've searched a lot, no solution corresponds to my research.
Basically, with the twitch API we have to make 2 API ...
0
votes
1
answer
302
views
how to make thunk HTTP POST request to Django rest api
I'm pretty new to this, so I will show you the error first and then display my thought process.
I am attempting to use a thunk (Http request in redux) to make a post request to my personal rest api in ...
1
vote
1
answer
765
views
Getting error in Next js with redux thunk TypeError: nextCallback is not a function [duplicate]
I am getting error in Next js while I am dispatching the action from index.js file
The main issue is with this function getServerSideProps, if i comment this function error gone, i don't understand ...
2
votes
2
answers
17k
views
Error: Expected the root reducer to be a function. Instead, received: 'undefined'
I keep running into this error!
Error: Expected the root reducer to be a function. Instead, received: 'undefined'
I've tried every answer I could find to no avail, here is all the pertinent stuff!
...
0
votes
1
answer
931
views
Improper type signature for `dispatch` method despite using "app dispatch" hook
Introduction
I'm using Redux Toolkit to add Redux support to a React application served by a Django app. We're using Typescript, and so we're following the Typescript Quick Start from the Redux ...
0
votes
2
answers
122
views
SICP Checking eval is a thunk?
In Sec 4.2.2 of SICP,
(define (list-of-arg-values exps env)
(if (no-operands? exps)
'()
(cons (actual-value (first-operand exps) env)
(list-of-arg-values (rest-operands exps)
...
0
votes
2
answers
761
views
return value from object function inside a map
I'm trying to run a getUserName function that is being called inside an Observable pipe, map, then another map. I can return a single value but I can't seem to map the passed array to then filter out ...
1
vote
1
answer
918
views
TypeError: (0 , _reduxjs_toolkit__WEBPACK_IMPORTED_MODULE_0__.createAsyncThunk) is not a function
Suddenly had this error after (it seems..) trying to deploy my client to Vercel.
I'm using NextJS and I'm fetching data server side with getStaticProps.
Tried reinstalling toolkit but the problem ...
1
vote
1
answer
99
views
Loading state before display new content
I'm trying to achieve optimistic UI loading with react and redux. This is my reducer:
const initState = {
user: {},
loading: true,
};
export default function (state = initState, action) {
...
1
vote
1
answer
2k
views
Why is my dispatch/console.log not firing when I call the action?
I was working on my final project for Flatiron and I came across a bug while working on my frontend. I tried many things, but always came back to this one issue. My callback function inside my ...
2
votes
0
answers
567
views
Problem with Jest and dispatch with async functions
I am working with React + Redux (with thunk) and I am using Jest for testing. I have the next code:
export const startUploading = (file) => {
return async(dispatch, getState) => {
...
0
votes
1
answer
927
views
Redux toolkit thunk disappears after getDefaultMiddlware config
My store looks like this:
export default configureStore({
reducer: {
sequencer: sequencerReducer,
editMode: editModeReducer,
tone: toneReducer,
app: appReducer,
},
middleware: (...
0
votes
1
answer
9k
views
React Redux Pagination
In the Case One:
Im doing a simple server-side pagination in rails and using react as front-end and redux as my state management. I have done all the things and the last thing remaining is to just ...
0
votes
1
answer
220
views
React redux doesn't return current state value
I have a problem with redux thunk in react. In the thunk file, I use to dispatch actions and change isSuccess and isLoading flag from the reducer, but in the component, after the API call, I get the ...
1
vote
2
answers
218
views
Racket: Creating a stream using a macro instead of a function
I'm currently attempting to create a stream using a macro, as shown below:
(define-syntax create-stream
(syntax-rules (using starting at with increment )
[(create-stream name using f starting at ...
1
vote
1
answer
415
views
How to transform class-based React-Redux code using Hooks
I am learning React/Redux and I am trying to refactor this code from class-based to functional/hooks-based code. The application is an exercise I am working on, it has three components Posts.js where ...
1
vote
0
answers
353
views
C++ thunk class implementation for forwarding C function callbacks to C++ member functions
I attempted implementing a "thunk" class in C++ that allows obtaining a C function pointer to pass to C code that eventually calls a C++ member function. A specific requirement was that it ...
2
votes
2
answers
1k
views
useEffect() cause re-renders and multiple requests to api
Problem
Functional component causes multiple re-renders causing multiple ajax requests. What is the solution for this?
This is my code.
export default function MyMenu() {
let menu = useStoreState(...
0
votes
1
answer
676
views
How to wait for data to be loaded before calling getState() in redux
I have an action, userAction, that will call an API to load data from the database, and I want to use that data within a separate action, calcAction, so that I can post to an API with the data from ...
0
votes
0
answers
171
views
How to use redux toolkit + redux thunks to create multiple async actions? [duplicate]
Here is the example from the documentation. I'm looking to implement a updateUser action with redux thunk, but I want for it to remain under the same slice as users for example. How can this be ...