Skip to content Skip to sidebar Skip to footer

Login Api Request Using React And Redux

I'm trying to make a small project using react & redux. The Main page for this project is the login. I already have a working api for login. Below is the code snippets from my

Solution 1:

DOCS:

npm install --save redux-thunk

Then, to enable Redux Thunk, use applyMiddleware():

import { createStore, applyMiddleware } from'redux';
import thunk from'redux-thunk';
import rootReducer from'./reducers';

// Note: this API requires redux@>=3.1.0const store = createStore(
  rootReducer,
  applyMiddleware(thunk)
);

Solution 2:

For async actions to work, you can use redux-thunk. To use it is pretty simple. Just load it into your middleware when you create your store.

import { applyMiddleware, createStore } from'redux';
import thunk from'redux-thunk';
import rootReducer from'../reducers';

exportdefault (initialState = {}) => {

  returncreateStore(
    rootReducer,
    initialState,
    applyMiddleware(thunk)
  );

};

Post a Comment for "Login Api Request Using React And Redux"