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
2 answers

dispatch is not a function Next.js +thunk load data user after login

When I'm try to getUserProfile() I receive that typeError that dispatch is not a function Unhandled Runtime Error Error: Actions must be plain objects. Use custom middleware for async actions. export const fetchUserProfile = (userData) => ({ type:…
1
vote
1 answer

How can i get the new state from the mapped props after dispatching an action

Hello guys , I'm just getting started with react Redux and I'm working on a simple crud app. I'm struggling with a problem of getting the current state of the store by a mapped props in component mapStateToProps . In the code bellow i have an action…
1
vote
1 answer

Axios React/Redux - not firing when using thunk action creator?

I am trying to integrate thunk in effort to get redux to allow axios to make asynchronous calls to a back end API i have. This is an existing project that is being moved over to adding in redux and typescript. For some reason I cannot get the…
Robert
  • 13
  • 4
1
vote
2 answers

How to supply object to thunk in typescript

There is an example here with a single property - "message" - supplied to thunk: https://redux.js.org/recipes/usage-with-typescript // src/thunks.ts import { Action } from 'redux' import { sendMessage } from './store/chat/actions' import {…
Steve Tomlin
  • 3,391
  • 3
  • 31
  • 63
1
vote
2 answers

Calling .then on a dispatch in axios/react

I have the following code: .... then(() => { return Promise.all([ dispatch(setAnimalCharacteristics(animalform)) ]) .then(() => { history.push("/animals); }) Is there a way to remove the…
lost9123193
  • 10,460
  • 26
  • 73
  • 113
1
vote
0 answers

What is the difference between Thunk and currying in JavaScript?

For currying,if we have a function like this: function multiply(x, y){ return x * y; } multiply(3, 5); // 15 Then its currying version is: function curriedMultiply(x) { return function(y) { return x * y; } } curriedMultiply(3)(5); //…
Chor
  • 833
  • 1
  • 5
  • 14
1
vote
1 answer

React Native Redux Persist not persisting state when combined with Redux Thunk

I am building a React Native app and I am using Redux. Redux Persist is working fine but when I add Redux Thunk, the store's state is not persisted. The value of the state.test variable does change to the one fetched from the api but when I restart…
1
vote
1 answer

Thunk won't dispatch from child component

I don't often post but I've been searching all day and this one's got me baffled. I have a Redux connected component "Homepage" which is loaded as the index by React Router. Within "Homepage"I have child component "EventCreate", which is connected…
Myka
  • 77
  • 1
  • 9
1
vote
2 answers

How to pass argument from component to redux action

I'm trying to pass the country name to the action in Redux from the React component but when it arrives in the action creator it becomes undefined. I think its something to do with the mapDispatchToProps() section below the component but I'm quite…
1
vote
1 answer

Redux Thunk and Async Actions

I'm getting two errors that I've narrowed down to be related to thunk and async actions. The first is “Error: Actions must be plain objects. Use custom middleware for async actions.” And the second is “Unhandled Rejection (TypeError): error.response…
this
  • 191
  • 13
1
vote
1 answer

Memory usage oddity (memory leak?)

I have the following type and two relevant functions that I intend to measure as a part of a large list fold: Type and access functions: data Aggregate a = Aggregate (Maybe a) (a -> Aggregate a) get :: Aggregate a -> Maybe a get (Aggregate get' _)…
Daniel Lovasko
  • 471
  • 2
  • 10
1
vote
1 answer

How to bind action creator to component in redux thunk

I'm trying to bind my action creator to react component. Please find below code snippet: import { updateCities } from '../../redux/actions/home'; class Home extends React.Component { constructor(props) { super(props); this.updateCities =…
user12342818
1
vote
1 answer

Thunk action creators dispatch another thunk action creators, but typescript throw an error. What type should i add?

How make typescript not complain or how to fix it? [ts] Argument of type '(dispatch: Dispatch) => void' is not assignable to parameter of type 'PostActionTypes'. Type '(dispatch: Dispatch) => void' is missing the following properties from…
1
vote
1 answer

Weird behavior of trampolining

Recently I've been doing some JS tasks on codewars and encountered this task Tail recursion with trampoline. Here we need to create thunk function and trampoline function in order to get rid of annoying RangeError: Maximum call stack size…
wlukla
  • 83
  • 4
1
vote
1 answer

question about esp Register usage in ATL Windowing Thunking

It's well know that ATL hooks a window to it's wndproc by thunking, which actually replace hwnd with this pointer in place and and jumps to the wndproc so that a call to wndproc(hwnd, ...) is actually wndproc(this, ...) . Below is the assembly code…
t.g.
  • 1,719
  • 2
  • 14
  • 25