in React JS by
Q:

What is Use of Redux thunk?

1 Answer

0 votes
by

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:

1

2

3

4

5

6

7

8

9

10

import{ createStore, applyMiddleware } from 'redux';

import thunk from 'redux-thunk';

import rootReducer from './reducers/index';

//Note: this API requires [email protected]>=3.1.0

const store= createStore(

     rootReducer,

     applyMiddleware(thunk)

);

Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
0 votes
0 votes
asked Jun 19, 2020 in React JS by JackTerrance
0 votes
asked Jun 19, 2020 in React JS by JackTerrance
0 votes
asked Mar 4, 2020 in React JS by JackTerrance
0 votes
asked Jul 2, 2019 in React JS by Venkatshastri
0 votes
0 votes
asked Mar 30, 2020 in React JS by amita rallin
0 votes
asked Mar 4, 2020 in React JS by JackTerrance
0 votes
0 votes
asked Mar 4, 2020 in React JS by JackTerrance
...