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:npmnpm install redux react-redux redux-devtools-extension redux-thunkYarnyarn add redux react-redux redux-devtools-extension redux-thunk
- After the installs finish, open the \package.jsonfile and quickly verify the packages were added to thedependenciesanddevDependencies.
Configure Redux
- Create the following file and configure Redux. - src\state.jsimport { 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 & devToolsconst enhancer = composeWithDevTools(middlewareEnhancer);const store = createStore(reducer, preloadedState, enhancer);return store;}export const initialAppState = {};export const store = configureStore(initialAppState);
- Verify the application compiles.