DEV Community

Discussion on: Fetching data from an api using React/Redux

Collapse
 
mrhassantariq profile image
Hassan Tariq

There a few methods that can help you using state variable in thunk function:

  1. You can export the state. Create a separate .js file and export the state object by using createStore(reducerName) method, then import that state object and use the getState() method to access the store.

  2. You can directly use getState in your app-thunk function by simply passing it as an argument like return (dispatch,getState) => {} and then use this getState() method to access the store.

There are some other methods but these should work.