I'm able to patch dispatch as a prop to my containers. I'm also able to pass in a copy of the state object to my containers. However, what I'd like to do is pass in the method, "getState()" to my containers as this.props.getState.

Is there any way to do this?

Why I want to do this:

The structure of my application is rather large, to simplify, I've tried to keep out any logic that doesn't actually need to be inside a container in seperate files (a "utilities" folder). For example, we have a custom backend, so all the code that deals with sending and receiving from the backend lives in ../utilities/api.js

Now, in order for these utilities to have access to the store, I have been importing the store from ../store/createStore.js directly. This is working well, but what I'd like to do instead is use dependency injection to pass in the dispatch and getState from the components that are calling the api, so it will be easier to write unit tests for these applications, and increase the modularity with other Redux apps we may be developing in the future.

Essentially, what I'd like to write is something like this:

//(Pesudocode) // ../containers/SomeComponent.js import api from '../utilities/api' class SomeComponent extends Component { constructor(props){ super(props); this.api = api(this.props.dispatch, this.props.getState); } someMethod(){ this.api.foo('bar'); } // etc. // pseudocode // in ../utilities/api.js export default function(dispatch, getState){ return { foo: function (bar){ // dispatch a complicated action which changes the state considerably dispatch(action.someAction(bar)) // get the new state. console.log("New State", getState()); } baz: function (razz, dugi){ // do something else } }

It is possible, I've found, to send in a copy of the current state when the class was constructed, but I really need the function getState() to call because some of those functions are asynchronous.

There might be other patterns, such as using async actions, but for what we're doing it works well.