Calling Dispatch function from a blank javascript file

后端 未结 2 1901
借酒劲吻你
借酒劲吻你 2020-12-15 20:02

So i\'m writing a React-Redux web app, and i call dispatch from my react components like this :

this.props.dispatch(someAction());

Now i ne

相关标签:
2条回答
  • 2020-12-15 20:51

    The dispatch function is a member of your redux store. If you created and exported your store in a module, it would be as easy as importing the store in your module and calling the dispatch function.

    Example:

    // store.js
    import { createStore } from 'redux'
    
    export default createStore(reducers)
    
    
    // somefile.js
    import store from './store'
    
    store.dispatch(someAction)
    
    0 讨论(0)
  • 2020-12-15 21:02

    The dispatch method is one of the store's methods. react-redux makes dispatch available to components as props via the provider, and mapDispatchToProps.

    You can dispatch directly from the store:

    store.dispatch(action)
    
    0 讨论(0)
提交回复
热议问题