Code Maze React Series - p-patel/software-engineer-knowledge-base GitHub Wiki

https://code-maze.com/react-series/

Preparing the Project and Creating Components

Create React app npx create-react-app <app name>

Add Bootstrap for styling npm i --save react-bootstrap bootstrap

inside index.js:

import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';

Stateless (functional components) vs. stateful (containers) components

Navigation and React Routing

React Routing Configuration, BrowserRouter, and Route

npm i --save react-router-dom install react router

npm i --save react-router-bootstrap used to merge a Bootstrap nav with a React-router nav

Navigation Menu

...

Creating the Not-Found Component

<Route path="*" component={NotFound} />

How to use Redux in React Application

npm i --save axios

npm i --save redux
npm i --save react-redux

npm i --save redux-rethunk send async requests with the Redux actions

Lazy Loading and HOC Component

  • Using the Redux repository inside a component and to use it to fetch data from the server
  • Lazily load components to demonstrate the advantage of lazy content loading

Implementing Redux

  • repositoryAction.js:
import { connect } from 'react-redux';
import * as repositoryActions from '../../../store/actions/repositoryActions';
const mapStateToProps = (state) => {     
    return {  
       data: state.data     
    } 
}
const mapDispatchToProps = (dispatch) => {
     return {
         onGetData: (url, props) => dispatch(repositoryActions.getData(url, props))     
    } 
} 
export default connect(mapStateToProps, mapDispatchToProps)(OwnerList);

Creating the Owner Component

To work with dates:

npm i --save react-moment
npm i --save moment

history.push('url') react routing (consider using instead)

Displaying Owner Result

  • use componentDidMount in OwnerList to dispatch `onGetData' on mount to retrieve owner data from API
  • set owners array to array using this.props.data.map()

Lazy Content Loading

  • load components asynchronously

How to Configure React Error Handling

⚠️ **GitHub.com Fallback** ⚠️