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
keeptrack
. - Run one of the following sets of commands:
npm
npm install redux react-redux redux-devtools-extension redux-thunknpm install --save-dev @types/react-reduxYarn
yarn add redux react-redux redux-devtools-extension redux-thunkyarn add --dev @types/react-redux - 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.ts
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: any) {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 interface AppState {}export const initialAppState: AppState = {};export const store = configureStore(initialAppState);Verify the application compiles.