front(react) back(node) mongoDB parei em: 01:59:00.
You Will Learn
HTML5 and CSS3: Semantic Elements, CSS Grid, Flexbox
React: Components, Props, Events, Hooks, Router, Axios
Redux: Store, Reducers, Actions
Node & Express: Web API, Body Parser, File Upload, JWT
MongoDB: Mongoose, Aggregation
Development: ESLint, Babel, Git, Github,
Deployment: Heroku
Watch React & Node Tutorial
Step by Step for building:
-
Create root folder and create react app
- mkdir amazonClone; cd amazonClone
- npx create-react-app frontend
- Remove unused files
- Create the base HTML in App.js
-
Share Code On Github
- Initialize git repository (git init) in root folder (amazonClone)
- commit changes
- login github on local repo
- create repo on github
- connect local repo to github repo
- push changes to github
-
Create MainRating and MainCardProduct Component
- create src/components/MainRating.js
- create div.card-rating in MainRating.js component
- style div.card-rating, span and last span
- Create src/components/MainCardProduct.js component
- use MainRating component in MainCardProduct component
-
Build ProductScreen and HomeScreen (pages) in folder screens
- install react-router-dom (v6) on frontend folder
- use BrowserRouter and make Routes for HomeScreen path: / exact and ProductScreen path product/:id in index.js
- create screens/HomeScreen.js (page)
- #HomeScreen: add product list (data.js) code there
- create screens/ProductScreen.js (page)
- #ProductScreen: add the onClick for singleProduct in home for redirect to path /product/this.id
- #ProductScreen: use FLEX GRID and create 3 columns for product-image(col-2), info(col-1) and action/addToCart(col-1)
-
Create Node.JS Server
- run npm init in root folder (amazonClone)
- Update amazonClone/package.json and in last name set "type": "module"
- Add .js to imports
- npm install express in root folder (amazonClone)
- create backend/server.js
- npm install nodemon (for auto re-running the aplication) in root folder (amazonClone)
- add start command as node backend/server.js in amazonClone/package.json -> scripts -> "start": nodemon --watch backend --exec node --experimental-modules backend/server.js
- require express
- create route for "/" return "backend is ready." in backend/server.js
- move data.js from frontend to backend/server.js
- create route for "/api/products" in backend/server.js (GET)
- return products
- run npm start
-
Load Products from Backend (GET "/api/products") in Frontend (and remove data.js in Frontend)
- Change the frontend/package.json -> set "proxy":"http://127.0.0.1:5000"
- cd amazonClone/frontend; npm install axios
- Edit amazonClone/frontend/src/screens/HomeScreen.js and make:
- [products, setProducts] = useState([]);
- useEffect() and define async:
- get data from "api/products" using axios.get();
- set the setProducts.
- call the there function in this.
- Change and remove data.js in this.
- Save All and new terminal -> amazonClone -> npm start and new terminal -> amazonClone/frontend -> npm start (for running the backend and frontend servers)
- create frontend/src/components/LoadingBox.js
- create frontend/src/components/MessageBox.js
- move ALL styles to frontend/src/index.css
- use them 2 new components in frontend/src/screens/HomeScreen.js
- create a variant class '.alert-danger' and use in MessageBox component from HomeScreen page
-
Install ESlint for code linting (ajuda a manter o padrão no código)
- Install VSCode eslint extension
- cd amazonClone; npm install -D eslint
- run ./node_modules/.bin/eslint --init
- Create ./frontend/.env
- Add SKIP_PREFLIGHT_CHECK=true
- CTRL + SHIFT + P -> eslint -> for config eslint
-
Add Redux to HomeScreen (page)
- cd amazonClone/frontend; npm install redux react-redux
- create /frontend/src/store.js
- initialState = {products: []}
- reducer = (state, action) => switch LOAD_PRODUCTS: {products: action.payload}
- export default createStore(reducer, initialState)
- Wrap with in frontend/src/index.js for injection the store on app
- Install the Redux DevTools extension for browser by developer suport
- npm install redux-thunk (thunk = conversão)
- Edit HomeScreen.js
- shopName = useSelector(state => state.products)
- const dispatch = useDispatch()
- useEffect(() => dispatch({type: LOAD_PRODUCTS, payload: data}))
- Add store to index.js