├── .babelrc
├── .gitignore
├── .postcssrc
├── New Text Document.txt
├── Notes
├── 4. Notes provided.txt
├── Assignment1.txt
├── Assignment10 + notes.txt
├── Assignment11 + notes.txt
├── Assignment12 + notes.txt
├── Assignment13 + notes.txt
├── Assignment3.txt
├── Assignment4.txt
├── Assignment5 + notes.txt
├── Assignment6 + notes.txt
├── Assignment8.txt
└── Assignment9 + notes.txt
├── README.md
├── index.html
├── package-lock.json
├── package.json
├── src
├── components
│ ├── About.js
│ ├── Body.js
│ ├── Cart.js
│ ├── Config.js
│ ├── Contact.js
│ ├── Error.js
│ ├── Footer.js
│ ├── Header.js
│ ├── InputControl.js
│ ├── ItemCardComponent.js
│ ├── Login.js
│ ├── MealComponent.js
│ ├── OrderHistory.js
│ ├── ProfileClass.js
│ ├── ProfileFunction.js
│ ├── RestaurantCard.js
│ ├── RestaurantMenu.js
│ ├── RestaurantMenuShimmer.js
│ ├── SearchBar.js
│ ├── ShimmerUI.js
│ ├── ShimmerUICard.js
│ ├── SignUp.js
│ └── UpdateCartOnUserChange.js
├── firebase.js
├── script.js
└── utils
│ ├── PathContext.js
│ ├── RestaurantContext.js
│ ├── SearchTextContext.js
│ ├── Store.js
│ ├── UserContext.js
│ ├── cartSlice.js
│ ├── useOnlineStatus.js
│ ├── useRestaurantMenu.js
│ ├── userSlice.js
│ └── utils.js
├── style.css
└── tailwind.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | // with options
2 | // {
3 | // "plugins": [ ["transform-remove-console" , {
4 | // "exclude" : ["log"]
5 | // }
6 | // ]]
7 | // }
8 | //no options
9 | {
10 | "plugins": [
11 | [
12 | "transform-remove-console"
13 | ]
14 | ]
15 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 | /.parcel-cache
8 | /dist
9 |
10 | # testing
11 | /coverage
12 |
13 | # production
14 | /build
15 |
16 | # misc
17 | .DS_Store
18 | .env.local
19 | .env.development.local
20 | .env.test.local
21 | .env.production.local
22 |
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 |
--------------------------------------------------------------------------------
/.postcssrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": {
3 | "tailwindcss": {}
4 | }
5 | }
--------------------------------------------------------------------------------
/New Text Document.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajeet1606/Namaste-React/0bdb17a3a606be45de3ba27872dd7c21d8a833e6/New Text Document.txt
--------------------------------------------------------------------------------
/Notes/4. Notes provided.txt:
--------------------------------------------------------------------------------
1 | Running Notes of @akshaymarch7 's session on 01-01-2023:
2 |
3 | Writing Scripts in package.json.
4 |
5 | *Q. What converts New Code to Older Code(For older version Browsers)?
6 | A: Babel
7 | We do not need to write polyfill. Babel does it automatically.
8 |
9 | npx - executing commands without downloading packages
10 | npm - will download required packages
11 |
12 | Note: Parcel will not remove console.log automatically. We need to configure for it. There is a package for it, named 'babel-plugin-transform-remove-console' either from babel website or npmjs website: npm install babel-plugin-transform-remove-console --save-dev /-D
13 |
14 | Usage: 1.via .babelrc (recommended)
15 | 2. via CLI
16 | 3. via NodeAPI
17 |
18 | React-key Reconciliation :
19 | When there are siblings in an array, we need to give keys for each sibling
20 | HW: Read about React-key Reconciliation from React Docs.
21 |
22 | React.createElement gives us an Object, which is then converted to html and puts into DOM
23 | JSX uses React.createElement (behind the scenes), which gives Object, and then into HTML, and it is put into DOM
24 | Babel does it. Babel converts JSX. JSX was developed by Facebook.
25 | Babel is must to use JSX.
26 |
27 | Q. Is JSX HTML inside JS? No.
28 | A: JSX is a HTML like Syntax, and not HTML inside JS.
29 |
30 | Babel: Compiler for JS.
31 | Read Babel Docs: babeljs.io
32 | Play with Babel in it's website.
33 | Babel comes along with Parcel.
34 |
35 | Also Go to it's GitHub Repo, and read about its algorithms.
36 |
37 | React Component:
38 | 2 Types:
39 | 1. Functional Component- NEW
40 | 2. Class Based Component - OLD
41 |
42 | Functional Comp is just a normal function that returns some piece of JSX, or a react element, or a function.
43 |
44 | Name of a Component starts with a Capital Letter (not mandatory, but good practice to use)
45 |
46 | If we have to write multiple lines to be returned in a component, we need to use ()and ; at the end.
47 |
48 | For Homework, use Normal Convention.
49 |
50 | Continued... Part 2
51 |
52 | Hope it was Helpful ??
53 | Notes Part 2:
54 |
55 | Diff b/n React Element & React Component:
56 |
57 | React Element is returning an Object.
58 | React Component is a function that returns JSX, or a react element, or a function.
59 |
60 | Syntax When rendering:
61 | For React Element, We use root.render(element_name);
62 | For React Component, We use Angular brackets: root.render();
63 |
64 | Any piece of Javascript code can be written within {}
65 |
66 | XSS - Cross site scripting (XSS) is an attack in which an attacker injects malicious executable scripts into the code of a trusted application or website. Attackers often initiate an XSS attack by sending a malicious link to a user and enticing the user to click it.
67 |
68 | JSX takes care of XSS.
69 |
70 | *Interview Q: Component Composition:
71 | A: Writing/ Passing component inside component.
72 |
73 | Home Work:
74 | 1. Read about React-key Reconciliation from React Docs.
75 | 2. Do Whatever Akshay did in the Session.
76 |
77 | *
78 |
79 | Hope it was Helpful ??
--------------------------------------------------------------------------------
/Notes/Assignment1.txt:
--------------------------------------------------------------------------------
1 | CHAPTER 1 - INCEPTION
2 |
3 | Ques: 1. What is Emmet?
4 |
5 | Ans: Emmet is a plug in for many popular text editors which greatly improves HTML & CSS workflow.
6 |
7 | Ques: 2. Difference between a Library & a Framework?
8 |
9 | Ans: Both frameworks and libraries are code written by someone else that is used to help solve common problems.
10 | A library is like going to Ikea. You already have a home, but you need a bit of help with furniture. You don’t feel like making your own table from scratch. Ikea allows you to pick and choose different things to go in your home. You are in control.
11 |
12 | A framework, on the other hand, is like building a model home. You have a set of blueprints and a few limited choices when it comes to architecture and design. Ultimately, the contractor and blueprint are in control. And they will let you know when and where you can provide your input.
13 |
14 | The Technical Difference
15 | The technical difference between a framework and library lies in a term called inversion of control.
16 |
17 | When you use a library, you are in charge of the flow of the application. You are choosing when and where to call the library. When you use a framework, the framework is in charge of the flow. It provides some places for you to plug in your code, but it calls the code you plugged in as needed.
18 |
19 | Ques: 3. What is CDN? Why we use it?
20 | Ans: A CDN improves efficiency by introducing intermediary servers between the client and the website server. These CDN servers manage some of the client-server communications. They decrease web traffic to the web server, reduce bandwidth consumption, and improve the user experience of your applications.
21 |
22 | Ques: 4. Why is React known as React?
23 | Ans: React is called "React" because of its core feature, which is its ability to "react" or respond dynamically to changes in data. React was originally created by Facebook in 2011 for use in their own web applications, and it was released as an open-source project in 2013.
24 | In a traditional JavaScript application, you need to look at what data changed and imperatively make changes to the DOM to keep it up-to-date.
25 | React takes a different approach.
26 |
27 | When your component is first initialized, the render method is called, generating a lightweight representation of your view. From that representation, a string of markup is produced, and injected into the document. When your data changes, the render method is called again. In order to perform updates as efficiently as possible, we diff the return value from the previous call to render with the new one, and generate a minimal set of changes to be applied to the DOM.
28 |
29 | Ques: 5. What is cross origin in script tag?
30 | Ans: The crossorigin attribute sets the mode of the request to an HTTP CORS Request. Web pages often make requests to load resources on other servers. Here is where CORS comes in. A cross-origin request is a request for a resource (e.g. style sheets, iframes, images, fonts, or scripts) from another domain.
31 |
32 | Ques: 6. Difference between React & ReactDOM?
33 | Ans: React: React is a javascript library, designed for building better user interfaces.
34 |
35 | React-DOM: React-DOM is a complimentary library to React which glues React to the browser DOM
36 |
37 | In a nutshell, Whenever we use component, classes, elements, etc. We’re using React and whenever we use methods like render() or findDOMNode() we’re using React-DOM.
38 |
39 |
40 | Ques: 7. Difference between React.development.js and React.production.js files via CDN?
41 | Ans: The development build is used - as the name suggests - for development reasons. You have Source Maps, debugging and often times hot reloading ability in those builds. The production build, on the other hand, runs in production mode which means this is the code running on your client's machine.
42 |
43 | Ques: 8: What is async and defer in script?
44 | Ans: When browser reads the web page, there are 2 things happening:
45 | 1. Parsing the HTML
46 | 2. Loading & Executing Scripts.
47 | There are 3 ways to define scripts in HTML file.
48 | 1. Direct way:
49 | Browser starts parsing HTML and when it reaches the scripts, it stopps, first it loads script & executes them then only further paring is done.
50 | 2. Using async:
51 | Script is loaded along with parsing but then parsing stopps for script execution, when it's completed then parsing resumes.
52 | 3. Using defer:
53 | Script is loaded along with parsing and when parsing is completed then script is executed.
54 |
55 | async doesn't maintain any order of script execution where as defer does.
--------------------------------------------------------------------------------
/Notes/Assignment10 + notes.txt:
--------------------------------------------------------------------------------
1 | Read List:
2 | -> Read about different routers in react-router-dom.
3 | -> read about constructor and super(props) in classes.
4 | -> React lifecycle diagram.
5 | -> componentDidMount can be async but useEffect not why?
6 |
7 |
8 | NOTES
9 |
10 |
11 | -> We can create childrens of children also in react route path. Apparently we've to create outlet in the parent body also when rendering.
12 |
13 | CLASS BASED COMPONENTS:
14 | -> render method is mandatory.
15 | -> we've a method, componentDidMount at the place of useEffect, so the order of execution is: contructor -> render -> componentDidMount.
16 | -> componentDidMount and useEffect in functional compo, are best place to make API calls.
17 |
18 |
19 |
20 |
21 | ASSIGNMENT
22 |
23 | => Why we use super(props) in constructor of class component?
24 | It allows to us to access 'this' keyword in constructor. It calls the constructor of parent class and assigns the props to this pointer.
25 |
26 | => Why can't we have the callback function of useEffect async?
27 | Using async function in useEffect is an error coz it return a promise and useEffect doesn't expect a callback fun to return promise, it should return nothing or a function. Still we can use async functions by defining a new inside/outside useEffect.
28 |
29 |
--------------------------------------------------------------------------------
/Notes/Assignment11 + notes.txt:
--------------------------------------------------------------------------------
1 | Notes:
2 |
3 |
4 | -> Parecel is a bundler, makes a single file for all of the code in our project.
5 | -> In large scale applications, one single file can make the network very slow hence we break the the code into multiple chunks (process called: Chunking, Code splitting, dynamic building, lazy loading, on demand loading) according to the intent of that.
6 | -> Now, every chunk is loaded into the browser only when it's needed, on demand loading.
7 | Such elements are imprted using lazy:
8 | const myCompoenent = lazy(() => import(path));
9 | -> So, when needed in browser, if it takes time to load and react wants to render it instantly and it's not loaded, react suspends the rendering and shows an error, to prevent this, to make react wait for loading, we SUSPENSE tag while making the route for our component.
10 | -> In this case, to avoid showing blank page while loading, we show shimmer UI using fallback attribute of suspense.
11 | }>
--------------------------------------------------------------------------------
/Notes/Assignment12 + notes.txt:
--------------------------------------------------------------------------------
1 | Reading list:
2 | Pure css
3 | Inline css
4 | SCSS vs SASS
5 | Styled components
6 | Component libraries: Tailwind, MUI, Chakra UI, Base UI, Ant design, Bootstrap.
7 |
8 | Read all pros and cons.
9 |
10 |
11 | Tailwind Pros:
12 | - CSS on the go,
13 | - reusability,
14 | - less bundle size,
15 | - flexible ui, less restriction.
16 |
17 |
18 | To-do:
19 | - install tailwind pkg.
20 | - read about the config file of tailwind.
21 | - instal tailwind css intellisense extension
--------------------------------------------------------------------------------
/Notes/Assignment13 + notes.txt:
--------------------------------------------------------------------------------
1 | NOTES + ASSIGNMENT
2 |
3 | Props Drilling:
4 | The process of passing data from Parent component to child component through a chain of other components, it goes through multiple other components to reach the destination.
5 | Disadvantages: Makes our code cluttered when the hierarchy becomes large.
6 | If parent changes the data, all the childs in the hierarchy are re rendered.
7 |
8 | Lifting State up:
9 | The process of lifting the state up is used to moving the state of a component to higher in the component hierarchy so that other components can also access it. It's done for code reusability and avoid passing props through multiple layers of components.
10 | Basically state is managed by the a parent and passed to childs as props.
11 |
--------------------------------------------------------------------------------
/Notes/Assignment3.txt:
--------------------------------------------------------------------------------
1 | ASSIGNMENT - 2: IGNITING OUR APP
2 |
3 |
4 | Ques 1: What is NPM?
5 | Ans: It's a package manager for JavaScript, it's defalt p. manager for JS runtime Nodejs. It consists of 2 parts:
6 | -> A CLI tool for publishing and downloading packages.
7 | -> An online repo that hosts JS packages.
8 |
9 | Soruce: https://www.freecodecamp.org/news/what-is-npm-a-node-package-manager-tutorial-for-beginners/
10 |
11 |
12 | Ques 2: What is Parcel/Webpack? It's need?
13 | Ans: These are bundlers mostly used for JS/TS that helps to minify, clean and make your code compact. Normally without using bundlers, in loading a web page, multiple files are transfered resulting in huge processing time but bundlers substantially reduce the time it takes and removes the unused code/ comments without modifying the functionality of code.
14 |
15 | Ques 3: What is .parcel-cache?
16 | Ans: Cache folder or .parcel-cache stores the information about the project when parcel builds it so that next time it don't have to parse and process everything from scratch. It's the reason behind Parcel being so fast in development.
17 |
18 | Ques 4: Difference between dependencies and devdependencies?
19 | Ans: Dependency is what your project needs to run like a library which provides some functionality that you call from your code. They are installed transitively. (A depends on B, we install A then B will also be installed)
20 |
21 | DevDependency is what we need during develpment or testing like compilers, test frameworks or documentation generators.
22 |
23 | Ques 5: What is Tree Shaking?
24 | Ans: When we import/export modules in JS, there are some unused code floating around. Tree Shaking or Dead Code Elimination means that unused code will not be included in the bundle during build process. Bundlers like parcel/webpack do this.
25 |
26 | Ques 6: Hot Module Replacement?
27 | Ans: It allows developers to update code changes in the running application without requiring a full browser refresh. It speeds up the development as the code changes are reflected immediately. It simply detects the changes in source code and injects the updated code into the application.
28 |
29 |
30 | Ques 7: What is NPX?
31 | Ans: It stands for Node Package eXecute. It's a node package runner which allows developers to run the JS packages available on NPM registry w/o even installing them.
32 |
33 | Ques 8: List down some super powers of Parcel?
34 | Ans:
35 | -> Builtin Support for various Technologies: It supports JS, TS, React, Vue, CSS.
36 | -> Universal Binding: It supports binding for both frontend & backend technologies.
37 | -> Hot Module Reloading: Update code changes in the running application without need of refreshing the broweser.
38 | -> Tree shaking: Exclude the unused code from the bundle during the build process.
39 | -> Zero Configuration: Needs no configuration in setting up hence super fast to start with.
40 | -> Speed: Super fast due to it's parallel processing and caching.
41 |
42 | Ques 9: What is .git-ignore?
43 | Ans: It is a file that tells Git which file/directory to ignore while tracking changes in a repository. We add the files here, which can be dynamically regenrated.
44 |
45 | Ques 10: Difference betweent package.json and package-lock.json?
46 | Ans: Package.json contains the metadata about the project and some functional dependencies which are required to run the project.
47 | Package-lock.json is created for locking the dependency with the locked version.
48 |
49 | Ques 11: Why should we not modify package-lock.json?
50 | Ans: - Can cause issue with consistency and integrity of your project's dependencies.
51 | - Can cause problems when collaborating with other devs as it can create difference in dependencies.
52 | - If you need to update, use the proper npm command.
53 |
54 | Ques 12: What are node-modules?
55 | Ans: It's a directory which is created when you install node.js packages in your project using package managers like NPM or YARN. It contains all the dependencies that your project needs to run.
56 | Don't push it to git: - Huge size, Redundant: can be generated using package-lock.json.
57 |
58 | Ques 13: What is dist folder in parcel?
59 | Ans: A directory which contains the final output of the build process, when you run parcel-build it takes all the files of your source code like HTML, CSS, JS and bundles them together to build a single package which can be deployed to a server or used in a production environment.
60 | Add it to git-igonre as it can be re-generated using parcel-build.
61 |
62 | Ques 14: Browserlists?
63 | Ans: It is a configuration file that allows devs to specify which browser and version their code should support.
64 |
65 | Ques 15: Bundlers?
66 | Ans: Bundlers are the tools which are used to make packages of our code and optimze it for deployment. They allow us to write modular code using modules and dependencies and bundle all of the code into a single package for production use. e.g: webpack, parcel.
67 |
68 | Ques 16: Caret ^ and Tilde ~
69 | Ans: Dependency versions are written in semver(semantic version) form, which consists of 3 parts, major, minor, patch. {1.2.3: major.minor.patch}.
70 | When we use ^ in front of version, it takes the latest minor version of given major version.
71 | When we use ~ in front of version, it takes the latest patch of given minor version.
--------------------------------------------------------------------------------
/Notes/Assignment4.txt:
--------------------------------------------------------------------------------
1 | ASSINMENT 3: LAYING THE FOUNDATION
2 |
3 |
4 | JSX => It's an extension of Javascript which allows us to write HTML like syntax in JavaScript. It makes it really easier to create and manipulate dynamic interfaces. This HTML like syntax is transformed into standard JS objects using a transpiler such a Babel.
5 |
6 | e.g: JSX: const element = ;
7 | Converted into JS: const element = React.createElement("button", { className: "btn btn-primary" }, "Click me");
8 |
9 | <--------------------------------------->
10 |
11 | React.createElement => It's a method provided by React library to create React elements programmatically using JS. It has 3 arguments: type of element, properties, child elements.
12 | e.g: React.createElement('div', { className: 'my-class' }, 'Hello, world!');
13 |
14 | <--------------------------------------->
15 |
16 | Benefits of JSX =>
17 | 1. Readability: Easy to read & understand the structure of UI.
18 | 2. Easy to learn: Similar to HTML
19 | 3. Improved performance: React can optimize the rendering of components when it detects changes in their state or props, which can reduce the number of DOM updates needed and improve performance.
20 | 4. Strong typing: Statically typed: Errors can be checked at compile time.
21 | 5. Customizable: define custom components and reuse.
22 |
23 | <--------------------------------------->
24 |
25 | Behind the Scenes of JSX =>
26 | JSX code is transpiled into JS:
27 | 1. Parsing: Through Babel -> AST
28 | 2. Transformation: AST -> JS, involves creating & updating DOM.
29 | 3. Bundling: Group up this JS file with other files/ dependencies by Parcel to make a package which is served to browser.
30 | 4. Execution: Bundled code is executed, React library takes control to create and update DOM.
31 |
32 | <--------------------------------------->
33 | Babel & parcel role in JSX =>
34 |
35 | Babel: Transpiler, converts JSX to JS or modern JS syntax to old so that browser can read. Have a plugin for JSX called @babel/plugin-transform-react-jsx, which converts JSX syntax into function calls that create React elements.
36 |
37 | Parcel: Bundler, takes all files, gives one package which is served to browser.
38 |
39 | <--------------------------------------->
40 |
41 | Components in React =>
42 | Building blocks of React application, they're re-usable pieces of code, represent a part of UI like bottom, forms, entire section.
43 | Two types:
44 | - Functional Component: Simple JS functions which take sime props and return a React element. Used for simple ones which don't require state or life cycle methods. Using a component inside another component is called composing component.
45 | - Class Components.
46 |
47 | <-------------------Coding Part-------------------->
48 |
49 |
50 | Create a Nested header Element using React.createElement(h1,h2,h3 inside a div with class “title”):
51 |
52 | const myHeading = React.createElement(
53 | "div",
54 | {
55 | className : "title"
56 | },
57 | [
58 | React.createElement(
59 | "h1",
60 | {
61 | id: "h1"
62 | },
63 | "This is H1"
64 | ),
65 | React.createElement(
66 | "h2",
67 | {
68 | id: "h2"
69 | },
70 | "This is H2"
71 | ),
72 | React.createElement(
73 | "h3",
74 | {
75 | id: "h3"
76 | },
77 | "This is H3"
78 | )
79 | ]
80 | );
81 |
82 |
83 | Create the same element using JSX:
84 |
85 | const myHeading1 = (
86 |
87 |
This is h1
88 |
This is h2
89 |
This is h3
90 |
91 | );
92 |
93 |
94 | Create a functional component of the same with JSX:
95 |
96 | const myHeading2 = () => (
97 |
98 |
This is h1
99 |
This is h2
100 |
This is h3
101 |
102 | );
103 |
104 | <--------------------------------------->
105 | Create a Header Component from scratch using Functional Components with JSX
106 | Add a Logo on left
107 | Add a search bar in middle
108 | Add User icon on right
109 | Add CSS to make it look nice
110 |
111 |
112 | Script file:
113 |
114 | const Header = () => {
115 | return (
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | );
128 | }
129 |
130 |
131 | const root = ReactDOM.createRoot(document.getElementById("root"));
132 |
133 | root.render();
134 |
135 | CSS file:
136 |
137 |
138 | .header{
139 | display: flex;
140 | justify-content: space-between;
141 | margin: 10px;
142 | padding: 5px;
143 | background-color: rgba(249, 202, 99, 0.607);
144 | border-radius: 50px;
145 | }
146 |
147 | .logo, .user{
148 | width: 50px;
149 | height: 50px;
150 | overflow: hidden;
151 | border-radius: 50%;
152 | display: flex;
153 | justify-content: center; /* center horizontally */
154 | /* align-items: center; center vertically */
155 | }
156 |
157 | .search{
158 | display: flex;
159 | justify-content: center; /* center horizontally */
160 | align-items: center; /* center vertically */
161 | }
162 |
163 | .search > input{
164 | width: 300px;
165 | height: 30px;
166 | }
167 |
168 | .search > input:hover, img:hover{
169 | cursor: pointer;
170 | }
171 |
172 | img{
173 | max-width: 100%;
174 | max-height: 100%;
175 | object-fit: cover;
176 | }
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 | ------------------------------------------------------ NOTES PROVIDED BY AKSHAY BHAIYA --------------------------------------------------
186 |
187 | Running Notes of @akshaymarch7 's session on 01-01-2023:
188 |
189 | Writing Scripts in package.json.
190 |
191 | *Q. What converts New Code to Older Code(For older version Browsers)?
192 | A: Babel
193 | We do not need to write polyfill. Babel does it automatically.
194 |
195 | npx - executing commands without downloading packages
196 | npm - will download required packages
197 |
198 | Note: Parcel will not remove console.log automatically. We need to configure for it. There is a package for it, named 'babel-plugin-transform-remove-console' either from babel website or npmjs website: npm install babel-plugin-transform-remove-console --save-dev /-D
199 |
200 | Usage: 1.via .babelrc (recommended)
201 | 2. via CLI
202 | 3. via NodeAPI
203 |
204 | React-key Reconciliation :
205 | When there are siblings in an array, we need to give keys for each sibling
206 | HW: Read about React-key Reconciliation from React Docs.
207 |
208 | React.createElement gives us an Object, which is then converted to html and puts into DOM
209 | JSX uses React.createElement (behind the scenes), which gives Object, and then into HTML, and it is put into DOM
210 | Babel does it. Babel converts JSX. JSX was developed by Facebook.
211 | Babel is must to use JSX.
212 |
213 | Q. Is JSX HTML inside JS? No.
214 | A: JSX is a HTML like Syntax, and not HTML inside JS.
215 |
216 | Babel: Compiler for JS.
217 | Read Babel Docs: babeljs.io
218 | Play with Babel in it's website.
219 | Babel comes along with Parcel.
220 |
221 | Also Go to it's GitHub Repo, and read about its algorithms.
222 |
223 | React Component:
224 | 2 Types:
225 | 1. Functional Component- NEW
226 | 2. Class Based Component - OLD
227 |
228 | Functional Comp is just a normal function that returns some piece of JSX, or a react element, or a function.
229 |
230 | Name of a Component starts with a Capital Letter (not mandatory, but good practice to use)
231 |
232 | If we have to write multiple lines to be returned in a component, we need to use ()and ; at the end.
233 |
234 | For Homework, use Normal Convention.
235 |
236 | Continued... Part 2
237 |
238 | Hope it was Helpful ??
239 | Notes Part 2:
240 |
241 | Diff b/n React Element & React Component:
242 |
243 | React Element is returning an Object.
244 | React Component is a function that returns JSX, or a react element, or a function.
245 |
246 | Syntax When rendering:
247 | For React Element, We use root.render(element_name);
248 | For React Component, We use Angular brackets: root.render();
249 |
250 | Any piece of Javascript code can be written within {}
251 |
252 | XSS - Cross site scripting (XSS) is an attack in which an attacker injects malicious executable scripts into the code of a trusted application or website. Attackers often initiate an XSS attack by sending a malicious link to a user and enticing the user to click it.
253 |
254 | JSX takes care of XSS.
255 |
256 | *Interview Q: Component Composition:
257 | A: Writing/ Passing component inside component.
258 |
259 | Home Work:
260 | 1. Read about React-key Reconciliation from React Docs.
261 | 2. Do Whatever Akshay did in the Session.
262 |
263 | *
264 |
265 | Hope it was Helpful ??
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
--------------------------------------------------------------------------------
/Notes/Assignment5 + notes.txt:
--------------------------------------------------------------------------------
1 | MY NOTES
2 |
3 | - JSX code can only have one parent so to wrap our all components, we use React.Fragment.
4 |
5 |
6 |
7 |
8 |
9 |
10 | To make it more cleaner we can write only empty tags also.
11 | <>
12 |
13 |
14 |
15 | >
16 |
17 | - When we modify our whole UI according to different situations dynamically it is called Config driven UI.
18 |
19 |
20 |
21 | ---------------------ASSIGNMENT--------------------
22 |
23 | Ques1: Is JSX mandatory for React?
24 | Ans: JSX is not mandatory but it's the preferred way to React code, it provides an HTML like syntax to write Javascript which makes it easier to write and understand. On the other hand we can write plain Javascript then we've to generate those HTML using JS which is quite complex and error prone.
25 |
26 | Ques2: Is ES6 mandatory for React?
27 | Ans: No, ES6 (ECMA Script 2015) birngs so many new features to JS like classes, template literals, arrow functions, destructuring and modules. Using it in react makes your code more concise, easier to read and maintain than compared to normal(in case that code can be written without ES6).
28 | Many important concepets of React like useState rely on ES6 itself.
29 |
30 | Ques3: {TitleComponent} vs {} vs {} in JSX?
31 | Ans: All 3 are different ways to render a React component depending on the user preference and personal needs.
32 | {TitleComponent}: Calling the component as react variable.
33 | {}: Calling in a self closing tag like html used when no props are passed.
34 | {}: Render using an opening and a closing tag, we can easily pass props, include some child components also.
35 |
36 | Ques4: How can I write comments in JSX?
37 | Ans: {/* This is a comment */}
38 |
39 |
40 | Ques5: What is and <>> ?
41 | Ans: In JSX, any component can return only one block of code, so we need to wrap our code in a parent element.
42 |
43 |
44 |
45 |
46 | But using the div tag to wrap our code, creates an actual div in our DOM, which is of no use. So, in React we use React.Fragment tag to wrap which makes no extra element in DOM.
47 | Since React 16, we can use it's shorthand version <>> to do the same.
48 |
49 | Ques6: What is Virtual DOM?
50 | Ans: DOM: Document Object model is a hierarchical representation of HTML elements on a web page.
51 | When something changes in our code, DOM is updated to reflect it on web page, updating DOM directly is explensive and slow hence React uses the concept of Virtual DOM, which a virtual lightweight representation of actual DOM. When we change something:
52 | React creates a new VDOM,
53 | Compares VDOM to old VDOM,
54 | Finds Changes, updates only the changed element in DOM. This process is called Reconciliation and done using Diffing algorithm. React fiber is new reconcilliation engine in React 16.
55 |
56 |
57 | Ques7: What is Reconciliation in React?
58 | Ans: When we update a state or props, React
59 | - Create updates the virtual DOM,
60 | - Compares new and old VDOM,
61 | - Finds the changes,
62 | - Updates the DOM,
63 | this process is Reconcilliation done using a Difing Algo.
64 | Few ways to improve Reconcilliation,
65 | - Provide Keys to elements, so when a similar kind of new element comes, it doesn't confuse and differentiates both.
66 | - ShouldComponentUpdate - A lifecycle method provided to you, you can tell which component would be re-rendered and which not.
67 |
68 |
69 | Ques8: What is React Fiber?
70 | Ans: Reimplementation of reconciliation algortihm, introduced in React 16, supports Asynchronous rendering, incremental updates, it's a unit of work. Earlier reconci. algo was using recursive approach, which could block the main thread especially in complex codes. It makes reconci. more efficient and fast.
71 | Async Rendering: When a task is being executed, React can stop this and start executing some other component complete that and come back and resume it.
72 | Incremental Updates: Update only the changed part of DOM tree instead of rerendering the whole tree.
73 |
74 |
75 | Ques9: Why we need keys in React? When do we need keys in React?
76 | Ans: Keys are used to give a unique identity to component childs, when react re-renders the component, it needs to know which element got changes/deleted/added. Using keys makes it easier to identify that. If a key is already seen, it doesn't re renders that, it a new key is found, it adds it to DOM to be re rendered. When keys match, attributes/properties of element are compared.
77 | Keys must be unique among it's siblings not the whole tree.
78 |
79 | Ques10: Can we use index as keys in React?
80 | Ans: Technically Yes but not recommended, using index of an array element as keys can lead to various problems if the array values change.
81 |
82 | Ques11: What is props in React? Ways to paas props?
83 | Ans: Props (properties) are inputs to a component which it takes from it's parent component. It allows to customize it's behaviour and appearance.
84 |
85 | Ques12: What is a Config Driven UI ?
86 | Ans: Enables developers to create and manage UI using congiguration data instead of hardcoding that.
87 | Benefits:
88 | - Flexibility: As configuration data is separated from codebase, we can easily modify it without touching code base.
89 | - Consistency: UI components can be reused throughout the application.
90 |
--------------------------------------------------------------------------------
/Notes/Assignment6 + notes.txt:
--------------------------------------------------------------------------------
1 | NOTES
2 |
3 | Reading List{
4 | - React File Structure
5 | -
6 | }
7 |
8 | - Ways to export a component:
9 | - Named Export: add export keyword in front of component definition, import will -> import {Name} from "file path"
10 | - Default Export: at the end of compo file: export default name: import -> import Name from "file path" (only one compo can be exported by defualt)
11 | - If we have exported multiple compos from a file, we can import them like: import * as XYZ from "file path" and later use it as: XYZ.Name.
12 |
13 |
14 | --------------------------------------------------------- ASSIGNMENT --------------------------------------
15 |
16 | Ques1: What is the difference between Named Export, Default export and * as export?
17 | Ans: Answered in Notes above.
18 |
19 | Ques2: What is the importance of config.js file?
20 | Ans: Few reasons for it's importance.
21 | -> Centralized Configuration: It stores all the configuration data at one place which makes it easy to access and modify them when needed.
22 | -> Separation of Concerns: Separating config data from the code makes it easier to maintain the code, developers can fully focus on building the product by using already available data instead of hard coding them.
23 | -> Security: Adding the API keys and other sensitive information in config file helps in protecting them from being exposed in code base.
24 |
25 | Ques3: What are React Hooks?
26 | Ans: Are functions, introduced in react 16.8, allows us to add state and lifecycle methods to functional components, earlier these were available only for class components.
27 | Popular hooks:
28 | -> useState: Allows functional component to use state, takes an inital value and returns an array of current value and a function to update the value.
29 | -> useEffect: Allows functional component to use lifecycle methods such as componentDidMount, componentDidUpdate. takes a function as a parameter and executes it after every render.
30 | -> useContext: helps to consume context element that were defined by the parent element using React.useContext API.
31 | -> useReducer
32 | -> useCallback.
33 |
34 |
35 | Ques4: Why do we need a useState Hook?
36 | Ans: Allows functional components to use state, earlier they were state less. Why?
37 | 1. Simplicity: When used with functional compo, makes it easier to understand and clear.
38 | 2. Performance: Reduces un-necessary re renders of compo.
39 |
--------------------------------------------------------------------------------
/Notes/Assignment8.txt:
--------------------------------------------------------------------------------
1 | EXPLORING THE WORLD
2 |
3 | Ques1: What are Microservices?
4 | Ans: Microservices is a Software Architecture that structures an application as a combination of small, independent services that communicate with other through APIs. Promotes Agility, Scalability and Resilience so each service can be build, updated and deployed without affecting the rest of the system.
5 |
6 |
7 | Ques2: What is a Monolith Architecture?
8 | Ans: Monolith architecuture is a traditional software design approach, which combines the whole software into a single unit, Each and every service like: User Interface, Business logic, frontend, backend, database, APIs all are processed into a single container.
9 | Any small change in any service leads to the whole software to be rebuilt, tested and deployed. Still widely used in small scale companies where Microservices isn't much evident.
10 |
11 |
12 | Ques3: What is the difference between Monolith and Microservice?
13 | Ans: Main different points:
14 | (i) Scalability: Monolithic Achitectures can't be scaled very much as a small change in any particular service leads to the whole application rebuilt, tested and redeployed. Where as in Microservice, all the services are independent of each other so changing anyone doesn't affect the rest of the system so scaling in easier.
15 |
16 | (ii) Resilience: In Monolithic Architecture, if one service fails, the application may go down but same in not to be necessarily true in case of Microservices as each service is independent of other.
17 |
18 | (iii)Agility: Monolithic can be too hard to modify and update as the size of application grows whereas Microservices are easier and agile to change.
19 |
20 |
21 | Ques4: Need of useEffect hook?
22 | Ans: Used to perform side effects, which affects the world outside the component. e.g. fetching the data from and API, updating the browser's title(a/c to the component name/current page openend), websocket.
23 | It takes two arguments: callback function with side effects, which tell what to do and an array of depenedencies, when changed, callback is called.
24 |
25 |
26 | Ques5: What is Optional Chaining?
27 | Ans: It's the ability to check whether a property of a JS object exists before going to access that. It saves us from getting a type error. operator => '?.'
28 |
29 |
30 | Ques6: What is Shimmer UI?
31 | Ans: When the website is loading, it's used to provide visual feedback to the users. It's a technique used to simulate the loading of the content by showing placeholders and animations which mimics the actual content to be loaded.
32 |
33 |
34 | Ques7: Conditional Rendering?
35 | Ans: Technique that allows us to render different content/component based on certain conditions. Commonly used in showing/hiding a data based on user interactions.
36 |
37 | Ex: function Greetings(props){
38 | const isLoggedin = props.isLoggedIn;
39 | if(isLoggedin) return
Welcome back
40 | else return
Login pls
41 | }
42 |
43 | ReactDOM.render(
44 | ,
45 | document.getElementById('root')
46 | );
47 |
48 |
49 | Ques8: What is CORS?
50 | Ans: Cross Origin Resource Sharing, is security feature implemented by web browsers that restricts web browsers to make request to a different domain than the one that served the page. It's a mechanism that allows servers to specify who can access their resources. Without CORS web pages would be able to access any resource on any domain which is risky.
51 |
52 | Ques9: Async and await?
53 | Ans: These are the keywords used for asynchronous programming. This is useful when performing a time consuming operations like reading and writing files which takes a long time, it would be inefficient to bolck the program's execution until the operation completes.
54 | Async & await work together, async defines a function that can be executed asynchronously, await keyword is to pause the function execution until the async operation completes. Allowing other tasks to executed in meantime.
55 |
56 | Ques10: What is the use of `const json = await data.json();
57 | Ans: Used to extract and parse JSON data from response object returned by an API call.
--------------------------------------------------------------------------------
/Notes/Assignment9 + notes.txt:
--------------------------------------------------------------------------------
1 | NOTES
2 |
3 | -> useEffect takes a callback function and a dependency array, the callback function:
4 | -> will be called when the elements of array changes.
5 | -> if array is empty: will be called once after inital render.
6 | -> if no array is passed, will render after each render.
7 |
8 | -> Don't create any component inside another component(before return point), rendering will be affected. Child will be created many times on every render.
9 | -> Don't create state variables inside ifelse or loop. Always keep inside a component.
10 |
11 | Creating Route:
12 | -> instal react-route-dom
13 | -> in app.js, import createBrowserRouter.
14 | -> Create appRouter,which defines the different paths to app and pages where to go.
15 | -> appRouter must be below the rendering of appLayout, the home page.
16 | -> Now, we've to provide this appRouter to our app, import RouterProvider.
17 |
18 | Two types of routing: Client side(data stays in client side, Single page apps) & server side(data comes from server whole page reloads, old method).
19 | -> use link component of react-router-dom, no reloads, single page application in moving to different pages.
20 |
21 |
22 | NESTED ROUTING:
23 | -> We want to keep our header and footer to be present always, so other pages will be rendered between them. Hence we make them child of appComponent by defining them in route config.
24 | -> Now we use something called, 'outlet' from react-router-dom, render it where we want other pages to be, it'll put them at it's place a/c to route.
25 |
26 |
27 | Dynamic Segments: Routing
28 |
29 | -> Used for random routes when they can be variable.
30 |
31 |
32 | ------------------------------------------ ASSIGNMENT ----------------------------------------------
33 |
34 | Ques1: What are various ways to add images into our App? Explain with code examples?
35 | Ans: -> Use url in img tag
36 | -> Store in your app: -> directly put the path in src or import the path then use as variable.
37 |
38 |
39 | Ques2: What would happen if we do console.log(useState())?
40 | Ans: useState returns an array of a variable with it's inital value and a function to modify it.
41 |
42 |
43 | Ques3: How will useEffect behave if we don't add a dependency array ?
44 | Ans: Dependency array defines the values on which useEffect callback function depends, it there no array, it'll be free and will be called after each render. So, empty array and no array are two different things here.
45 |
46 |
47 | Ques4: SPA
48 | Ans: Single Page application is a web application that loads a single HTML page and dynamically updates the elements without requireing the full page relaod.
49 |
50 | Ques5: Client Side & Server Side Routing?
51 | Ans: Client: Routing is handled totally on client side, fast, SPA built on it.
52 | Server: Routing is handled on server side code, on demand, server responds to a html page.
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Namaste-React
2 | This repository contains all the learnings and notes I created while learning React JS from #Namaste-React Course, food studio is a project, built while learning the concepts.
3 |
4 | ## Food-Studio
5 | Order food from the confort of your home, we show the latest restaurants available in your city, with all the details.
6 | Pick a dish, add to cart, place order, get delivered.
7 |
8 | ## Tech - Stack
9 | 1. Frontend Library: React JS
10 | 2. Styling: Tailwind CSS
11 | 3. Database: Firebase
12 | 4. Bundler: Parcel
13 | 5. Authentication: Firebase-Auth
14 | 6. State Management: Redux Toolkit
15 |
16 | ## Working of project
17 | 1. We fetch the restaurants of your city from Swiggy API, getting the live data.
18 | 2. Display them with Area name, Cuisines Category and Ratings.
19 | 3. Search Restaurants by Name.
20 | 4. For any restaurant, you can checkout all the different type of dishes available with details and prices per quantity.
21 | 5. Add to cart
22 | 6. Authenticate yourself
23 | 7. Place Order.
24 |
25 | ## Improvements to make
26 | 1. Not responsive for Mobile phones
27 | 2. Cart data is not stored anywhere, it should be in local storage for not logged in users to avoid losing on refresh page.
28 | 3. While Signing up, user name is not displayed in the profile point instantly, needs a refresh. It doesn't happen in logging in process.
29 | 4. Improve the design, take user address and payment details.
30 | 5. Add feature to search different cities, currently working for Prayagraj only.
31 |
32 | ## How to run on your local
33 | 1. Clone the repository
34 | 2. Run ```npm init```
35 | 3. Run ```npm start```.
36 | 4. Make sure you've allow CORS extension installed in your browser.
37 |
38 | Drop a 💫 if you liked it.
39 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Food Studio
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "namaste-react",
3 | "version": "1.0.0",
4 | "description": "This is the start of Namaste React",
5 | "scripts": {
6 | "start": "parcel index.html",
7 | "build": "parcel build index.html",
8 | "test": "jest"
9 | },
10 | "author": "Ajeet Patel",
11 | "license": "ISC",
12 | "devDependencies": {
13 | "@babel/core": "^7.21.3",
14 | "babel-plugin-transform-remove-console": "^6.9.4",
15 | "parcel": "^2.8.3",
16 | "postcss": "^8.4.21",
17 | "process": "^0.11.10",
18 | "tailwindcss": "^3.3.1"
19 | },
20 | "dependencies": {
21 | "@reduxjs/toolkit": "^1.9.5",
22 | "firebase": "^9.21.0",
23 | "react": "^18.2.0",
24 | "react-dom": "^18.2.0",
25 | "react-loading-skeleton": "^3.2.0",
26 | "react-redux": "^8.0.5",
27 | "react-router-dom": "^6.10.0"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/components/About.js:
--------------------------------------------------------------------------------
1 | import { useLocation } from "react-router-dom";
2 | import { useContext, useEffect } from "react";
3 | import PathContext from "../utils/PathContext";
4 |
5 | const About = () => {
6 | const {setCurrentPath} = useContext(PathContext);
7 | const {pathname} = useLocation();
8 |
9 | useEffect(() => {
10 | setCurrentPath(pathname);
11 | }, [])
12 |
13 | return (
14 | <>
15 |
16 | ″Our mission is to elevate the quality of life for the urban consumer
17 | with unparalleled convenience. Convenience is what makes us tick. It's
18 | what makes us get out of bed and say, "Let's do this."
19 |
20 |
21 |
22 |
23 |
What’s In Store For The Future?
24 |
25 |
Food Studio has grand plans to be India’s most loved hyperlocal player. It aims to be the most accessible platform on the network - reimagining the meaning of convenience in the country through a variety of service offerings.