Call send function from empty javascript file

So, I am writing a React-Redux web application, and I am invoking dispatch from my responsive components as follows:

this.props.dispatch(someAction());

Now I need to call send from a javascript function that is not a React component, so how do I import a send function and use it in this case? Thank.

+4
source share
2 answers

The function dispatchis a member of your store abbreviation . If you created and exported your store in a module, it would be easier to import the store into your module and call the function dispatch.

Example:

// store.js
import { createStore } from 'redux'

export default createStore(reducers)


// somefile.js
import store from './store'

store.dispatch(someAction)
+10
source

store . react-redux dispatch provider mapDispatchToProps.

store:

store.dispatch(action)
+2

Source: https://habr.com/ru/post/1681217/


All Articles