Questions tagged [thunk]

A parameterless closure (functional programming) or a function generated by a compiler to aid runtime linking with a dynamic library function.

  • In functional programming, a thunk is an anonymous and parameterless function (closure), used to pass lazily evaluated expressions.
  • In C++, a thunk is a compiler generated function which optimizes virtual function calls.
  • On systems which support dynamic linking, a thunk is often automatically inserted to provide a place for the runtime linker to insert code for invoking the actual implementation found in a library.
184 questions
1
vote
0 answers

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 Async Thunk method calling the API as many times…
1
vote
1 answer

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, payload) => ({ type, payload…
Tom Foxtrot
  • 567
  • 4
  • 14
1
vote
1 answer

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'. Property 'type' is missing in type 'AppThunk' but…
reClicked
  • 15
  • 1
  • 6
1
vote
1 answer

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": ["hey", "foo"], "resultValue": 0}, "type":…
Dmitri K
  • 11
  • 3
1
vote
2 answers

useSelector cannot make real time update once the state is changed in react

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 like this: function Search({fetchDataApi}) { …
Joanne Lee
  • 45
  • 5
1
vote
2 answers

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... import { createStore, applyMiddleware } from…
Roy Kolak
  • 605
  • 1
  • 6
  • 18
1
vote
1 answer

Getting error in Next js with redux thunk TypeError: nextCallback is not a function

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 what is the issue in this function index.js…
1
vote
1 answer

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 persist. import { createSlice, createAsyncThunk }…
sniv
  • 101
  • 1
  • 4
1
vote
1 answer

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) { switch (action.type) { case…
Nemus
  • 3,879
  • 12
  • 38
  • 57
1
vote
1 answer

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 dispatch is not firing. So while I may be interested to…
1
vote
2 answers

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 i0 with increment delta) (letrec …
Chris
  • 11
  • 2
1
vote
1 answer

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 I fetch a list of posts from typicode.com. Each…
Monika
  • 87
  • 1
  • 7
1
vote
0 answers

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 works with C code that does not pass a void * context…
Andy
  • 109
  • 1
  • 10
1
vote
1 answer

Calling an action within another one in Redux using TypeScript

Suppose that I have these 2 actions (as an example) for "creating category" and "loading all categories". I need to load all categories every time I create a new category successfully, so, I need to call "loadAllCategories" action within…
Aspian
  • 1,865
  • 3
  • 24
  • 31