Use the React-Redux library’s
Use the React-Redux library’s connect function to give a component access to a Redux store
Use the React-Redux library’s applyMiddleware function to configure one or more middleware when creating a store
Write a thunk action creator to make an asynchronous request to an API and dispatch an action when the response is received
Higher-order components, or HOCs, receive a React component as an argument and return a new component.
Ex:
/login
if there is no currentUserId export const ProtectedRoute = ({ component: Component, path, currentUserId, exact }) => {
return (
<Route
path={path}
exact={exact}
render={(props) =>
currentUserId ? <Component {...props} /> : <Redirect to="/login" />
}
/>
);
};
/
if there is a currentUserId export const AuthRoute = ({ component: Component, path, currentUserId, exact }) => {
return (
<Route
path={path}
exact={exact}
render={(props) =>
currentUserId ? <Redirect to="/" /> : <Component {...props} />
}
/>
);
};
We use the React-Redux library to improve how React Components interact with the Redux store.
The React-Redux library has two main parts- The <Provider />
component and connect
function.
connect
subscribes React components to specific slices of Redux state and action creators
To use the React-Redux library we must * npm install react-redux
Other installs in this lesson: * redux-logger
* redux-thunk
Lecture Video Google Drive Folder