question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Actions Are Called Twice

See original GitHub issue

Very cool library, I like the approach. Thanks for building and OSing it!

I’ve swapped in redux-pack for redux-thunk and rewritten an action called getBroadcasts from this redux-thunk action:

export function getBroadcasts() {
  return async (dispatch) => {
    dispatch({ type: 'GET_BROADCASTS_INITIATED' });

    try {
      const { data: { results } } = await api.get('/broadcasts');
      dispatch({ type: 'GET_BROADCASTS_SUCCEEDED', payload: results });
    } catch (error) {
      dispatch({ type: 'GET_BROADCASTS_FAILED', payload: error });
    }
  };
}

to this redux-pack action:

export function getBroadcasts() {
  return {
    type: 'GET_BROADCASTS',
    promise: api.get('/broadcasts')
  }
}

What I observe in the console when the relevant page loads is that while the redux-thunk action was called only once:

thunk

the redux-pack action is called twice, and returns once with an undefined payload, and once with a successful payload:

pack

I assume this is expected behavior, I just wanted to confirm.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
evandaviscommented, Jan 13, 2017

It looks like there are intentionally 2 dispatches, on start and then on one of success or failure.

The nice part of having the 3-phase action (old way) is that you can have other reducers react to those actions. I think you lose that here, but maybe I’m missing something?

0reactions
fredguestcommented, Jan 19, 2017

Closing as this has been confirmed as expected behavior. Thanks for the discussion!

Read more comments on GitHub >

github_iconTop Results From Across the Web

useReducer dispatch being called twice - Stack Overflow
It's almost working fine, but it is executing the actions twice. The toggle function for example is putting the attribute done to true,...
Read more >
Why are my Redux actions being dispatched twice? : r/reactjs
It is because the uuid object gets created again on each render so the reference to that object is never the same. That's...
Read more >
useReducer dispatch calls reduce twice · Issue #16295 - GitHub
There is no "problem". React intentionally calls your reducer twice to make any unexpected side effects more apparent. Since your reducer is ...
Read more >
React 18 - Avoiding Use Effect Getting Called Twice
For React Hooks in React 18, this means a useEffect() with zero dependencies will be executed twice. Here is a custom hook that...
Read more >
Action is called twice in single request in grails
Sometime it happens that controller's action/method is called twice back to back.At first time it is called with the right parameter you have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found