Git Product home page Git Product logo

Comments (12)

wenqiW avatar wenqiW commented on May 18, 2024 8

found it is not related with redux-thunk, please delete it. Sorry

from redux-thunk.

TrySound avatar TrySound commented on May 18, 2024 2

@sun2rise Thunk isn't promise middleware. Your action creators can look like this

const actionCreator = () => dispatch => {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve();
    }, 10);
  }).then(() => {
    dispatch({ type: 'ACTION_TYPE' });
  });
};

store.dispatch(actionCreator()).then(() => {
  console.log('The end of poem');
});

from redux-thunk.

ericwooley avatar ericwooley commented on May 18, 2024

@wenqiW What was it, I am having the same issue

from redux-thunk.

AlessandroAnnini avatar AlessandroAnnini commented on May 18, 2024

@wenqiW, @ericwooley i am having the same issue... where am i wrong?

from redux-thunk.

TrySound avatar TrySound commented on May 18, 2024

@sun2rise Did you return promise in action creator?

from redux-thunk.

AlessandroAnnini avatar AlessandroAnnini commented on May 18, 2024

This is the object that i return from my action:

return new Promise(function (resolve, reject) {
    resolve({
      type: types.STORE_MEDIA_DATA_AUDIO_TRACKS,
      payload: fixedData
    });
  });

and this is the error i got:

VM5118:1180 Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.

I got this in my configureStore.js

import thunk from 'redux-thunk';

const store = createStore(rootReducer, initialState, compose(
    // Add other middleware on this line...
    applyMiddleware(thunk),
    window.devToolsExtension ? window.devToolsExtension() : f => f // add support for Redux dev tools
    )
  );

from redux-thunk.

ericwooley avatar ericwooley commented on May 18, 2024

For the record, my problem wasn't redux-thunk, it ended up being a different middle ware that was interfering with this.

from redux-thunk.

AlessandroAnnini avatar AlessandroAnnini commented on May 18, 2024

So redux-thunk is only for timing stuff? i have to chain actions, should i use redux-promise? I have to wait for a very short operation to complete and then call the next action

from redux-thunk.

ericwooley avatar ericwooley commented on May 18, 2024

@sun2rise If your having a similar problem to me, try disabling other middle wares and see if it works

IIRC the one that was the issue for me was the redux-localstorage middleware

from redux-thunk.

AlessandroAnnini avatar AlessandroAnnini commented on May 18, 2024

thanks @ericwooley but i only (try to) use redux-thunk for now.. all i do is

applyMiddleware(thunk)

in my createStore function

from redux-thunk.

markbrocato avatar markbrocato commented on May 18, 2024

I'm having this issue. I tried removing all other middleware but that didn't fix it. It looks like the dispatch method is just returning the action object, not a promise.

from redux-thunk.

markbrocato avatar markbrocato commented on May 18, 2024

The action is being returned from here: https://github.com/reactjs/redux/blob/master/src/createStore.js#L181

from redux-thunk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.