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

What is the correct way of multiple dispatches to the thunk in Redux from the componentDidMount of a React Component?

As the title suggests, I'm trying to dispatch multiple actions from the same component's componentDidMount hook. MovieDetails.js class MovieDetails extends Component { componentDidMount() { const movieId = this.props.movieId …
hellraiser999
  • 91
  • 2
  • 13
0
votes
1 answer

Getting "Uncaught TypeError: Cannot read property 'results' of undefined " when mapping the data from API using Redux

I'm trying to map data from the movieDB api in React & Redux and getting the error: Uncaught TypeError: Cannot read property 'results' of undefined For better understanding, here's my code. reducers/moviesReducer.js const initialState = { …
hellraiser999
  • 91
  • 2
  • 13
0
votes
1 answer

Deleting post with React Redux API delete request

When I console log this.props I get an array with post.id and I want to make onClick function to remove this item from the list and do not show on the page. What is wrong with my code there? So this is what I have: export const deletePost = id =>…
Thomas Rositsky
  • 177
  • 1
  • 3
  • 10
0
votes
0 answers

TypeError: Object(...) is not a function when using redux compose() function

I'm receiving this error and don't really know why, since I've copied the code from a tutorial. If I remove the compose function and just use applyMiddleware without using reactReduxFirebase and reduxFirestore, everything works correctly. import…
Filip
  • 855
  • 2
  • 18
  • 38
0
votes
1 answer

Why are the arguments to a thunk wrapped inside of an object?

I'm trying to understand thunks in redux: const thunk = ({ dispatch, getState }) => next => action => { if (typeof action === 'function') { return action(dispatch); } return next(action); }; And I'm having trouble understanding why the…
user2387766
0
votes
1 answer

Moxios always retuning empty when using thunk and axios

I'm stuck trying to mock my axios function which is always returning empty: LoginAction: export function loginUser(email, password) { return function(dispatch) { return axios .post(`${API_URL}/users/authenticate`, { email, password }, {…
lost9123193
  • 10,460
  • 26
  • 73
  • 113
0
votes
0 answers

axios query string thunk + graphql

I am getting the following error from an axios thunk: ExceptionsManager.js:82 messed up in createMeeting: Error: Request failed with status code 400 at createError (createError.js:16) at settle (settle.js:17) at…
Eric Grossman
  • 219
  • 1
  • 4
  • 9
0
votes
1 answer

Run secondary action after promise regardless of outcome?

I found this previous thread (How to perform same action regardless of promise fulfilment?), but it's 5 years old and references winjs is a kludge. What I would like to do is load a list of data elements. I've got local copies of the list and local…
lowcrawler
  • 6,777
  • 9
  • 37
  • 79
0
votes
1 answer

"getFirebase() is not a function" after running npm install

I have been working on a little react app and it has been going well, I thought but I am nowhere near the level of understanding I would like. I have run into a snag that leaves me dumbfounded. All was well in my code. I opened another app in my…
Steve
  • 367
  • 3
  • 11
0
votes
1 answer

Redux reducer, append multiple api paginated requests to state

I am building an app. This app needs to request a woocommerce API for product data. The API will only allow 100 items at a time, so I have had to call this request 4 times with dynamic page parameters. My aim for this data is to have a reducer…
0
votes
2 answers

Is there a difference in expressiveness of thunk or pair based deferred types?

Given are two types that both represent deferred computations: const deferThunk = thunk => ({run: thunk}); const deferPair = (f, args) => ({run: [f, args]}); const tap = f => x => (f(x), x); const log = console.log; const tx =…
user5536315
0
votes
0 answers

Are functions in a C++/CLI native class compiled to MSIL or native x64 machine code?

This question is related to another question of mine, titled Calling MASM PROC from C++/CLI in x64 mode yields unexpected performance problems. I din't receive any comments and answers, but eventually I found out myself that the problem is caused by…
SBS
  • 806
  • 5
  • 13
0
votes
1 answer

How to encode a Deferred type with Church?

With functions we can abstract from any type. Here is the Option type as an example: const Some = x => y => k => k(x); const None = y => k => y; const sqr = n => n * n; const run = f => t => t(f); const x = Some(5) (0), y =…
user10675354
0
votes
1 answer

What is the purpose of thunkToPromise in the co coroutine lib?

I know co is kind of outdated but I am still interested in how it works. I find it hard to understand the purpose of the thunkToPromise function, though: function thunkToPromise(fn) { var ctx = this; return new Promise(function (res, rej) { …
user10675354
0
votes
1 answer

Using thunks: Why isn't my code printing sequentially?

I'm trying to understand thunks. I'm going through Kyle Simpson's Rethinking Async JS course on Lynda. I have this code: function makeThunk(fn) { var args = [].slice.call(arguments, 1); return function(cb) { args.push(cb); …
Asool
  • 13,031
  • 7
  • 35
  • 49