Lab 23 Redux: Installation & Configuration
Objectives
- Install Redux and related packages
- Configure Redux
Steps
Install Redux
- Open a
command prompt
(Windows) orterminal
(Mac). - Change the current directory to
working\keeptrack
. - Run one of the following sets of commands:
npm
npm install redux@4 react-redux@8 redux-devtools-extension redux-thunk@2
Yarn
yarn add redux@4 react-redux@8 redux-devtools-extension redux-thunk@2
- After the installs finish, open the
\package.json
file and quickly verify the packages were added to thedependencies
anddevDependencies
.
Configure Redux
Create the following file and configure Redux.
src\state.js
import { createStore, applyMiddleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension';
import { combineReducers } from 'redux';
const reducer = combineReducers({});
export default function configureStore(preloadedState) {
const middlewares = [ReduxThunk];
const middlewareEnhancer = applyMiddleware(...middlewares);
//Thunk is middleware
//DevTools is an enhancer (actually changes Redux)
//applyMiddleware wraps middleware and returns an enhancer
// to use only thunk middleware
// const enhancer = compose(middlewareEnhancer);
//to use thunk & devTools
const enhancer = composeWithDevTools(middlewareEnhancer);
const store = createStore(reducer, preloadedState, enhancer);
return store;
}
export const initialAppState = {};
export const store = configureStore(initialAppState);Verify the application compiles.