Google News
logo
ReactJS - Interview Questions
What is Use of Redux thunk?
Redux thunk acts as middleware which allows an individual to write action creators that return functions instead of actions. This is also used as a delay function in order to delay dispatch of an action if a certain condition is met. The two store methods getState() and dispatch() are provided as parameters to the inner function.
 
In order to activate Redux thunk, we must first use applyMiddleware() method as shown below:
import{ createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers/index';
 
//Note: this API requires redux@>=3.1.0
 
const store= createStore(
     rootReducer,
     applyMiddleware(thunk)
);
Advertisement