Ecom website
Ecom website
1) Header
2) Carousel(Slider)
3) Product Card
4) Product listing
5) Search
6) Cart
7) AddToCart
8) Checkout page
9) Wishlist
10)Categories
11) Payment
Yes(Absolutely hard)
document.createElement(div)
React
Advantages
Virtual DOM
Code Reusability
Component(Part of point 2)
Uni Directional
Single page application(React router)
Disadvantages
Bad SEO(Search Engine optimisation)
Next js - (https://nextjs.org/)
Vite
Webpack
https://codesandbox.io/
Component in React
1) function
2) Html written inside javascript is known as JSX(Javascript xml notation)
3) Return jsx
4) Export the function to be used wherever it is needed
JSX and js can be used interchangeably both work JSX is better so that you know it is
a react component
Add function
function add() {
return 2+3;
}
Making it dynamic
function add(a,b) {
return a+b;
}
When you want to get the data you would have to create an API and the API would be
returning the data to the frontend from the backend
https://designer.mocky.io/design/confirmation
1) Fetch
2) Axios
3) AJAX (https://www.w3schools.com/js/js_ajax_http.asp)
Interview question
1) Build your own fetch
JSON
[
{
"id": 1,
"category": 1,
"title": "Apple iPhone 14",
"price": 100000
},
{
"id": 2,
"category": 1,
"title": "Apple iPhone 13",
"price": 70000
},
{
"id": 3,
"category": 1,
"title": "Google Pixel 7",
"price": 50000
},
{
"id": 4,
"category": 1,
"title": "Nokia 1100",
"price": 2000
},
{
"id": 5,
"title": "Samsung Galaxy S10",
"price": 100000
},
{
"id": 6,
"category": 1,
"title": "Sony Xperia S10",
"price": 100000
},
{
"id": 7,
"category": 2,
"title": "Apple Macbook Air M1",
"price": 120000
},
{
"id": 8,
"category": 2,
"title": "HP Pavilion E5",
"price": 70000
},
{
"id": 9,
"category": 3,
"title": "Tshirt",
"price": 1000
},
{
"id": 10,
"category": 3,
"title": "Jeans",
"price": 7000
}
]
1) Wait for the data (you are not taking advantage of the async behaviour of
js)
2) Rerender the component once data arrives
Hooks in JS
Helper function
Helper
Is used to remove the redundant tasks and provide them in a simple function
Something that is going to happen again and again would be put in a hook
useState hook
useState would return a state variable and a function to set that state variable
setProducts([]) // correct
I want to call the fetch function only one on the first function call and not again and
again
useEffect- This is going to control the amount of times a function would be called basis
a dependency array
Only once
useEffect(function(){
}, [])
everytime
useEffect(function(){
})
}, [products])
Every time products is changes the function inside useEffect would be called again and
again
1) Components
a) ComponentName
i) ComponentName.jsx
ii) ComponentName.css
iii) index.js
2) Pages
a) PageName
i) PageName.jsx
ii) PageName.css
iii) index.js
3) Utils
4) Context
5) Hooks
https://www.freecodecamp.org/news/javascript-modules/
AddToCart Component
Two buttons + and -
Show quantity
Array of objects
Object of objects
let cart = {
1: {
Id: 1,
title: “samsung”,
Price: “20000”,
Quantity: 2,
},
2: {
Id: 2,
title: “samsung2”,
Price: “30000”,
Quantity: 1,
}
cart[product.id].quantity += 1
Prop drilling: Process of passing a prop from the top most parent down to the place
where it is needed to be used is known as prop drilling
Context:
I will provide you with a wrapper (psuedo parent) which could be used to provide all the
global state and functions to all the children.
Redux, MobX
If you are changing anything in the state variable then the component would be
rerendered?
20
Rerender
State variable is
let cart = {
1: {
Id: 1,
title: “samsung”,
Price: “20000”,
Quantity: 2,
},
2: {
Id: 2,
title: “samsung2”,
Price: “30000”,
Quantity: 1,
}
}
React wont know for change of a key that something in the object has changed because
the object keys cant be compared for rerendered
https://javascript.info/currying-partials
https://www.thatjsdude.com/
https://www.toptal.com/javascript/interview-questions
1) Keys
2) Virtual dom
3) Hooks
4) Context
5) Redux
6) State management
7) Custom hook
https://github.com/siddharthInterviewbit/Ecom-Masterclass