├── .gitignore
├── Blogs
├── 01.StoryOfReact.md
├── 02.HowToStartReactApp.md
├── 03.Components.md
├── 04.JSX.md
├── 05.StateHooks.md
├── 06.TwoWayBinding.md
├── 07.StateLiftingUp.md
├── 08.RenderingUpdatingConditionaling_Lists.md
├── 09.DynamicScopying_CSS.md
├── 10.DebuggingWays.md
├── 11.ReactFragments.md
├── 12.ReactPortals.md
├── 13.useRef()Hook.md
├── 14.useEffectHook.md
├── 15.useReducer()Hook.md
├── 16.comboOFuseEffectAnduseReducer.md
├── 17.useContext()Hook.md
├── 18.React.memo().md
├── 19.useCallback()Hook.md
├── 20.StateSecduling.md
├── 21.useMemo()Hook.md
├── 22.Frontend-Backend-Communication.md
├── 23.CustomHooks.md
├── ReactForms.md
└── ReactRouter.md
├── EssentailCommands.md
├── License.md
├── Projects
├── AddUser
│ ├── Screenshot from 2023-01-01 01-51-23.png
│ ├── build
│ │ ├── asset-manifest.json
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ ├── robots.txt
│ │ └── static
│ │ │ ├── css
│ │ │ ├── main.dce1127a.chunk.css
│ │ │ └── main.dce1127a.chunk.css.map
│ │ │ └── js
│ │ │ ├── 2.14e73586.chunk.js
│ │ │ ├── 2.14e73586.chunk.js.LICENSE.txt
│ │ │ ├── 2.14e73586.chunk.js.map
│ │ │ ├── main.6377feb0.chunk.js
│ │ │ ├── main.6377feb0.chunk.js.map
│ │ │ ├── runtime-main.36ce5d8f.js
│ │ │ └── runtime-main.36ce5d8f.js.map
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ ├── readme.md
│ └── src
│ │ ├── App.js
│ │ ├── App.module.css
│ │ ├── Components
│ │ ├── AddUserForm.js
│ │ ├── AddUserForm.module.css
│ │ ├── AddedUser.js
│ │ ├── UpdateWindow.js
│ │ ├── UpdateWindow.module.css
│ │ ├── UserInfo.js
│ │ └── UserInfo.module.css
│ │ ├── UI
│ │ ├── ModelWindow.js
│ │ └── ModelWindow.module.css
│ │ ├── index.css
│ │ └── index.js
├── Create-Read-React-Frontend-Backend-Communication
│ ├── Screenshot from 2023-01-14 18-35-59.png
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ ├── readme.md
│ └── src
│ │ ├── App.css
│ │ ├── App.js
│ │ ├── components
│ │ ├── AddMovie.js
│ │ ├── AddMovie.module.css
│ │ ├── Movie.js
│ │ ├── Movie.module.css
│ │ ├── MoviesList.js
│ │ └── MoviesList.module.css
│ │ ├── index.css
│ │ └── index.js
├── Expense_Tracker
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ ├── readme.md
│ └── src
│ │ ├── App.js
│ │ ├── components
│ │ ├── Chart
│ │ │ ├── Chart.css
│ │ │ ├── Chart.js
│ │ │ ├── ChartBar.css
│ │ │ └── ChartBar.js
│ │ ├── Expenses
│ │ │ ├── ExpenseChart.js
│ │ │ ├── ExpenseDate.css
│ │ │ ├── ExpenseDate.js
│ │ │ ├── ExpenseFilter.css
│ │ │ ├── ExpenseFilter.js
│ │ │ ├── ExpenseITem.js
│ │ │ ├── ExpenseItem.css
│ │ │ ├── Expenses.css
│ │ │ ├── Expenses.js
│ │ │ ├── ExpensesList.css
│ │ │ └── ExpensesList.js
│ │ ├── NewExpense
│ │ │ ├── ExpenseForm.css
│ │ │ ├── ExpenseForm.js
│ │ │ ├── NewExpense.css
│ │ │ └── NewExpense.js
│ │ └── UI
│ │ │ ├── Card.css
│ │ │ └── Card.js
│ │ ├── index.css
│ │ └── index.js
├── Firebase Custom Hooks Task Manager
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ └── src
│ │ ├── App.js
│ │ ├── components
│ │ ├── NewTask
│ │ │ ├── NewTask.js
│ │ │ ├── TaskForm.js
│ │ │ └── TaskForm.module.css
│ │ ├── Tasks
│ │ │ ├── TaskItem.js
│ │ │ ├── TaskItem.module.css
│ │ │ ├── Tasks.js
│ │ │ └── Tasks.module.css
│ │ └── UI
│ │ │ ├── Section.js
│ │ │ └── Section.module.css
│ │ ├── hooks
│ │ └── use-http.js
│ │ ├── index.css
│ │ └── index.js
├── Food Ordering App
│ ├── Screenshot from 2023-01-14 18-26-26.png
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ ├── readme.md
│ └── src
│ │ ├── App.js
│ │ ├── Assets
│ │ └── meals.jpg
│ │ ├── Components
│ │ ├── Cart
│ │ │ ├── Cart.js
│ │ │ ├── Cart.module.css
│ │ │ ├── CartIcon.js
│ │ │ ├── CartItem.js
│ │ │ └── CartItem.module.css
│ │ ├── Layout
│ │ │ ├── Header.js
│ │ │ ├── Header.module.css
│ │ │ ├── HeaderCartButton.js
│ │ │ └── HeaderCartButton.module.css
│ │ ├── Meals
│ │ │ ├── AvailableMeals.js
│ │ │ ├── AvailableMeals.module.css
│ │ │ ├── MealItem
│ │ │ │ ├── MealForm.js
│ │ │ │ ├── MealForm.module.css
│ │ │ │ ├── MealItem.js
│ │ │ │ └── MealItem.module.css
│ │ │ ├── Meals.js
│ │ │ ├── MealsSummary.js
│ │ │ └── MealsSummary.module.css
│ │ └── UI
│ │ │ ├── Card.js
│ │ │ ├── Card.module.css
│ │ │ ├── Input.js
│ │ │ ├── Input.module.css
│ │ │ ├── Model.js
│ │ │ └── Model.module.css
│ │ ├── Store
│ │ ├── CartProvider.js
│ │ └── cart-context.js
│ │ ├── index.css
│ │ └── index.js
├── FormValidation
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ └── src
│ │ ├── App.js
│ │ ├── Store
│ │ └── auth-context.js
│ │ ├── components
│ │ ├── Home
│ │ │ ├── Home.js
│ │ │ └── Home.module.css
│ │ ├── Login
│ │ │ ├── Login.js
│ │ │ └── Login.module.css
│ │ ├── MainHeader
│ │ │ ├── MainHeader.js
│ │ │ ├── MainHeader.module.css
│ │ │ ├── Navigation.js
│ │ │ └── Navigation.module.css
│ │ └── UI
│ │ │ ├── Button
│ │ │ ├── Button.js
│ │ │ └── Button.module.css
│ │ │ └── Card
│ │ │ ├── Card.js
│ │ │ └── Card.module.css
│ │ ├── index.css
│ │ └── index.js
└── ToDo-App
│ ├── package.json
│ ├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
│ ├── readme.md
│ └── src
│ ├── App.css
│ ├── App.js
│ ├── components
│ ├── CourseGoals
│ │ ├── CourseGoalItem
│ │ │ ├── CourseGoalItem.css
│ │ │ └── CourseGoalItem.js
│ │ ├── CourseGoalList
│ │ │ ├── CourseGoalList.css
│ │ │ └── CourseGoalList.js
│ │ └── CourseInput
│ │ │ ├── CourseInput.js
│ │ │ └── CourseInput.module.css
│ └── UI
│ │ └── Button
│ │ ├── Button.js
│ │ └── Button.module.css
│ ├── index.css
│ └── index.js
├── Readme.md
├── package-lock.json
└── react-js-logo-no.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | */node_modules/
2 | */build/
3 | node_modules
4 |
--------------------------------------------------------------------------------
/Blogs/01.StoryOfReact.md:
--------------------------------------------------------------------------------
1 | # React 101: Understanding How It Works and Why It's Different from Other Frontend Frameworks
2 |
3 | >In this blog post, we'll dive into the inner workings of React, one of the most popular frontend frameworks for building web applications. We'll explore how React works behind the scenes and how it's different from other frontend frameworks like Angular and Vue. We'll also cover some of the key features and benefits of using React, and provide some helpful resources for learning more. Whether you're new to React or have some experience with it, this post will give you a better understanding of how it works and how it fits into the world of frontend development.
4 |
5 | ## Why we need react.js ?
6 |
7 | "In traditional JavaScript, we would have to manually write every piece of HTML tag and its corresponding functionality. However, in large applications like Netflix, we want smooth transitions without having to fetch and load new HTML files every time a user makes a request. To solve this problem, React introduces custom HTML components. These components can be written in a declarative rather than imperative style, allowing us to create reusable and modular code for our application."
8 |
9 | ## What are SPAs?
10 |
11 | "React JS allows us to build single page applications (SPAs). This means that when a user clicks on a link, rather than fetching a new HTML file from the server, React can dynamically update the JavaScript code to change what is displayed on the screen. Only the initial request needs to be made to the server, and subsequent actions do not require additional requests to be made."
12 |
13 | ## How React code actually loads behind the scenes?
14 |
15 | "In a React application, there is typically only one index.html file located in the public folder. This file is the only one that is loaded because React is a single page application. The index.html file contains a root `
` element, which can be accessed in the index.js file located in the src folder. This JavaScript file is only loaded when the application is initially loaded and it renders the ` `component, which serves as the root of all the other components in the application. The App.js file contains the code for the App component and any other components that are attached to it. These components are typically located in a separate components folder."
16 |
17 | ### How actually it works behind the scenes?
18 |
19 | Behind the scenes, React uses a system called the "virtual DOM" to efficiently update the DOM and minimize the number of actual DOM manipulations that need to be performed. When the state of a component changes, React will compare the virtual DOM representation of the updated component to the previous version, and only make the necessary changes to the actual DOM.
20 |
21 | ## Difference between react.js , vue.js and angular.js?
22 |
23 | "React is a component-based framework that relies on community libraries to provide additional features. Angular is also component-based, but it has a larger feature set built into the framework itself and uses TypeScript. Vue.js is a component-based framework that falls somewhere in between React and Angular in terms of its reliance on external libraries and features."
24 |
--------------------------------------------------------------------------------
/Blogs/02.HowToStartReactApp.md:
--------------------------------------------------------------------------------
1 | # Get Up and Running with Your First React App: A Step-by-Step Guide
2 |
3 | >In this blog post, we'll walk through the process of setting up and starting a new React app from scratch. Whether you're a beginner or an experienced developer, this step-by-step guide will provide you with the information you need to get started with your first React app project. We'll cover topics like installing the necessary tools, creating a new project, and adding features and components to your app. By the end of this post, you'll have a solid foundation for building your own React app and you'll be ready to take your skills to the next level.
4 |
5 | 1. **Install Node.js**: React is built using JavaScript, so you'll need to have Node.js installed on your computer to run React apps. You can download and install Node.js from the official [website](https://nodejs.org/) or using a package manager like [Homebrew](https://brew.sh/) (for macOS) or [Chocolatey](https://chocolatey.org/) (for Windows).
6 |
7 | 2. **Install the React CLI**: The React command-line interface (CLI) is a tool that allows you to create and manage React projects. To install the React CLI, open a terminal and run the following command:
8 |
9 | ```sh
10 | npm install -g react-cli
11 |
12 | ```
13 |
14 | 3. **Create a new project**: Once you have the React CLI installed, you can create a new React project by running the following command:
15 |
16 | This will create a new directory called "my-app" with the basic structure and files needed for a React app.
17 |
18 | 4. **Install dependencies**: Navigate to the project directory and run the following command to install the required dependencies:
19 |
20 | ```sh
21 | npm install
22 |
23 | ```
24 |
25 | 5. **Start the development server**: Once the dependencies have been installed, you can start the development server by running the following command:
26 |
27 | ```sh
28 | npm start
29 |
30 | ```
31 |
32 | This will start the development server and open a new browser window with your React app. Any changes you make to the code will be automatically reflected in the browser.
33 |
34 | ## Conclusion
35 |
36 | - Go to the folder
37 | - Open the terminal in that folder
38 | - Run these commands
39 |
40 | ```sh
41 | npm init react-app my-app
42 | cd my-app
43 | npm start
44 | ```
45 |
--------------------------------------------------------------------------------
/Blogs/03.Components.md:
--------------------------------------------------------------------------------
1 | # An introduction to understanding components and how they work in React
2 |
3 | >In this blog post, we'll explore the concept of components in React, one of the fundamental building blocks of modern web development. We'll look at what components are, how they work, and how they can be used to build reusable and scalable web applications. Whether you're new to React or have some experience with it, this post will give you a deeper understanding of how components work and how they fit into the React ecosystem.
4 |
5 | ## What are the components in the React?
6 |
7 | "Components in React typically consist of a combination of HTML, JavaScript, and CSS. These components are designed for reuse and can be built from scratch or created by combining other components. They are essentially just JavaScript functions that return JSX, which is a syntax extension of JavaScript that allows you to write HTML-like code in your JavaScript files. Components are useful for creating modular and reusable code, and they can be an important tool for building and maintaining large applications."
8 |
9 | ## Components of a Component
10 |
11 | - Make a component >> src >> components
12 | - add css file by just importing
13 | - function name as a component name
14 | - function also contains a paramter object of pros
15 | - function can also contains some logic
16 | - contain a function return some JSX
17 | - use className=""
18 | - use javascript in JSX as a {}
19 | - Add aslo nested components(pass props.-- into its custom attribute)
20 | - JSX returing wrapper element never be a Component (Build Custom Wrapper Components) for this.
21 |
22 | ```js
23 | import React from "react";
24 |
25 | function Message(props) {
26 | return
{props.text}
;
27 | }
28 | ```
29 |
--------------------------------------------------------------------------------
/Blogs/04.JSX.md:
--------------------------------------------------------------------------------
1 | # The Power of JSX: How It Makes Building Components in React a Breeze
2 |
3 | >In this blog post, we'll take a deep dive into JSX, the syntax extension used in React for defining components and rendering UI. We'll explore how JSX works with components in React, and how it allows you to write concise and expressive code for building web applications.
4 |
5 | ## What are JSX?
6 |
7 | "JSX (JavaScript XML) is a syntax extension for JavaScript that allows you to write HTML-like code in your JavaScript files. It is essentially just HTML written in a JS file, and all the HTML is ultimately converted to XML. In other words, JSX is a sugar-coated version of HTML tags. You can see the underlying code in the main.js file through developer tools.
8 |
9 | In JSX components, there must be only one root element returned, not multiple root elements. It is important to note that JSX is not actually HTML, but rather a syntax developed by the React team to resemble HTML. If you need to add classes, you should use the className attribute instead of the class attribute."
10 |
11 | There are a few things to keep in mind when working with JSX:
12 |
13 | - You must wrap your JSX elements in a parent element, or you will get a syntax error.
14 |
15 | - You can use JavaScript expressions within JSX by enclosing them in curly braces.
16 |
17 | - You can use JSX elements as the children of other JSX elements, allowing you to build complex UI from smaller, reusable pieces.
18 |
19 | - You can use the React.createElement function to create JSX elements dynamically at runtime.
20 |
21 | ```js
22 | const element =
39 | );
40 | ```
41 |
--------------------------------------------------------------------------------
/Blogs/05.StateHooks.md:
--------------------------------------------------------------------------------
1 | # State Management in React: A Comprehensive Guide
2 |
3 | > If you're new to React, you might be wondering what state is and how it fits into the picture. Or, if you're an experienced developer, you might be looking for ways to improve your state management skills. Either way, this post is for you. We'll cover everything you need to know about state in React, from the basics to advanced techniques and best practices.
4 |
5 | ## What is state in the react and What is the stateHook?
6 |
7 | useState is a hook in React that allows you to add state to functional components. Prior to the introduction of hooks, only class-based components could have state.
8 |
9 | Here's an example of how you might use useState in a functional component:
10 |
11 | ```js
12 | import { useState } from "react";
13 |
14 | function Example() {
15 | // Declare a new state variable, which we'll call "count"
16 | const [count, setCount] = useState(0);
17 |
18 | return (
19 |
20 |
You clicked {count} times
21 |
22 |
23 | );
24 | }
25 | ```
26 |
27 | In this example, we are using useState to create a state variable called count and a function called setCount that allows us to update the value of count. The initial value of count is passed as an argument to useState, which in this case is 0.
28 |
29 | When the button is clicked, the setCount function is called with the new value for count, which is the current value of count plus 1. This causes the component to re-render and the new value of count is displayed.
30 |
31 | Behind the scenes, useState is implemented using a concept called a "state hook." When the component is rendered, the state hook function creates a piece of state and a function for updating that state, and stores them in an array. The array destructuring syntax (const [count, setCount] = useState(0)) is used to extract the current value of the state (count) and the function for updating it (setCount) from the array.
32 |
33 | You can use useState multiple times in a single component to create multiple pieces of state. For example:
34 |
35 | ```js
36 | import { useState } from "react";
37 |
38 | function Example() {
39 | const [count, setCount] = useState(0);
40 | const [name, setName] = useState("Alice");
41 |
42 | return (
43 |
44 |
You clicked {count} times
45 |
46 |
Your name is {name}
47 |
48 |
49 | );
50 | }
51 | ```
52 |
--------------------------------------------------------------------------------
/Blogs/06.TwoWayBinding.md:
--------------------------------------------------------------------------------
1 | # Mastering Two-Way Binding: Tips and Techniques for Working with Data in Real-Time
2 |
3 | > Two-way binding is a powerful tool for building dynamic and interactive web applications. It allows you to bind data to UI elements in real-time, so that any changes to the data are immediately reflected in the UI and vice versa. In this post, we'll explore the ins and outs of two-way binding, including how to set it up, how to work with it, and how to use it to build reactive and responsive apps
4 |
5 | ## How we can add Two-Way Binding in react.js ?
6 |
7 | Two-way binding in React allows you to synchronize the value of a form element with the state of a component. This is often useful when you want to ensure that the user's input is valid and up-to-date.
8 |
9 | Here is an example of how to implement two-way binding in a React component:
10 |
11 | ```js
12 | import React, { useState } from "react";
13 |
14 | function MyForm() {
15 | // Declare a state variable and set its initial value to the empty string
16 | const [value, setValue] = useState("");
17 |
18 | // Handle changes to the input element
19 | const handleChange = (event) => {
20 | setValue(event.target.value);
21 | };
22 |
23 | return (
24 |
27 | );
28 | }
29 | ```
30 |
31 | In this example, we use the useState hook to create a state variable called value and a function called setValue to update it. The input element's value attribute is set to the current value of value, and the onChange event handler is used to update value when the user types into the input.
32 |
33 | This creates a two-way binding between the input element and the component's state, allowing the value of the input to be automatically updated as the user types, and the input to be automatically updated when the value of value changes.
34 |
35 | You can also use two-way binding with other form elements, such as textareas and select elements. Simply set the value attribute and use an onChange event handler to update the component's state.
36 |
--------------------------------------------------------------------------------
/Blogs/07.StateLiftingUp.md:
--------------------------------------------------------------------------------
1 | # Data Flow in React: A Comprehensive Guide to Moving Data Between Components
2 |
3 | > One of the most powerful features of React is its ability to move data between components. In this post, we'll explore the different techniques you can use to pass data between components, including props, state, and context. We'll also cover best practices for managing data flow in a React application, and how to avoid common pitfalls
4 |
5 | ## How we can move data from Child-to-Parent Component Communication (Bottom-up) in React.js?
6 |
7 | Passing a callback function as a prop: You can pass a callback function as a prop to the child component, and have the child component invoke the callback function when it needs to communicate with the parent. For example:
8 |
9 | ```js
10 | // Parent component
11 | function Parent() {
12 | const handleDataFromChild = (data) => {
13 | // Do something with the data from the child component
14 | };
15 |
16 | return ;
17 | }
18 |
19 | // Child component
20 | function Child(props) {
21 | const sendDataToParent = () => {
22 | props.onDataFromChild("Some data");
23 | };
24 |
25 | return ;
26 | }
27 | ```
28 |
29 | In this example, the Parent component renders the Child component and passes a callback function called handleDataFromChild as a prop to the child. The Child component has a button that, when clicked, invokes the sendDataToParent function, which in turn calls the onDataFromChild callback function with some data as an argument. This causes the handleDataFromChild function in the parent component to be executed, and the data from the child is passed to the parent.
30 |
31 | This is a simple and effective way to move data from a child component to a parent component, but it can become cumbersome if you need to pass data from multiple children to the same parent, or if you need to pass data from a deeply nested child to a parent that is several levels up the component tree. In these cases, you might want to consider using a state management library or the context API.
32 |
33 | ## How we can achieve the lifting The State Up ?
34 |
35 | "Lifting the state up" is a technique for managing state in a React application that involves moving shared state from a child component to a parent component. This is often useful when multiple child components need to access and modify the same piece of state, as it allows you to avoid having to pass the state down the component tree as props.
36 |
37 | Here's an example of how to lift the state up:
38 |
39 | ```js
40 | import React, { useState } from "react";
41 |
42 | function Parent() {
43 | // Declare a state variable and set its initial value
44 | const [value, setValue] = useState("");
45 |
46 | // Pass the state and setter function down as props to the children
47 | return (
48 |
;
66 | }
67 | ```
68 |
69 | In this example, the Parent component has a state variable called value that is shared by the Child and Sibling components. The Parent component passes the value and setValue functions down as props to the children, allowing them to both access and modify the shared state.
70 |
71 | By lifting the state up to the parent component, we can avoid having to pass the state down the component tree as props, and we can easily manage the shared state in one place.
72 |
73 | It's important to note that, while lifting the state up can be a useful technique for managing state, it can also lead to a deeper component tree and make it more difficult to understand the flow of data in your application. It's a good idea to carefully consider whether lifting the state up is the right approach for your use case.
74 |
--------------------------------------------------------------------------------
/Blogs/08.RenderingUpdatingConditionaling_Lists.md:
--------------------------------------------------------------------------------
1 | # The Power of Lists: How to Render Them in React with Ease
2 |
3 | >If you're new to React, you might be wondering how to render lists in your components. Or, if you're an experienced developer, you might be looking for ways to improve your list rendering skills.We'll look at different techniques for rendering lists, including the map function, the for loop, and the useEffect hook. We'll also cover best practices for rendering lists in a React application, and how to optimize your code for performance.
4 |
5 | ## How we can render a list in React ?
6 |
7 | In React, you can render a list by using the map method on an array, and returning a JSX element for each item in the array. Here's an example of how you could render a list of numbers:
8 |
9 | ```js
10 | import React from "react";
11 |
12 | function NumberList(props) {
13 | const numbers = [1, 2, 3, 4, 5];
14 | const listItems = numbers.map((number) => (
15 |
{number}
16 | ));
17 | return
{listItems}
;
18 | }
19 | ```
20 |
21 | In this example, the map method iterates over the numbers array and creates a new array of li elements. The resulting array is then rendered as a ul element, with each li element representing an item in the list.
22 |
23 | It's important to note that each item in the list should have a unique key prop, which helps React identify which items have changed, been added, or been removed. In the example above, the key prop is set to the string version of the number.
24 |
25 | ## How we achieve the updated new array without losing previous data in it in react by using useState function?
26 |
27 | To update the state of an array in React without losing the previous data, you can use the useState hook and the spread operator (...). The useState hook allows you to add state to functional components, and the spread operator allows you to create a new copy of an array, rather than mutating the original array.
28 |
29 | Here's an example of how you could use useState and the spread operator to add an item to an array:
30 |
31 | ```js
32 | import { useState } from "react";
33 |
34 | function Example() {
35 | const [items, setItems] = useState([]);
36 |
37 | const addItem = () => {
38 | setItems([...items, "new item"]);
39 | };
40 |
41 | return (
42 |
43 |
44 |
45 | {items.map((item, index) => (
46 |
{item}
47 | ))}
48 |
49 |
50 | );
51 | }
52 | ```
53 |
54 | In this example, the useState hook is used to add state to the Example component, with an initial value of an empty array. The addItem function creates a new copy of the items array using the spread operator, and adds a new item to the end of the array. The updated array is then passed to the setItems function, which updates the state of the items array.
55 |
56 | When the addItem function is called, the Example component will re-render, and the new item will be added to the list. This approach ensures that the previous data in the items array is not lost, and the state is updated in an immutable way.
57 |
58 | ## How we display the conditional content in React ?
59 |
60 | In React, you can display conditional content by using a combination of JavaScript and JSX. Here's an example of how you could use an if statement to conditionally render content:
61 |
62 | ```js
63 | import React from "react";
64 |
65 | function Example(props) {
66 | const showContent = props.showContent;
67 |
68 | if (showContent) {
69 | return
This content is visible
;
70 | } else {
71 | return
This content is not visible
;
72 | }
73 | }
74 | ```
75 |
76 | In this example, the Example component renders a div element with different content based on the value of the showContent prop. If the showContent prop is true, the component will render the first div element. If the showContent prop is false, the component will render the second div element.
77 |
78 | You can also use a ternary operator (?) to concisely render conditional content in a JSX expression:
79 |
80 | ```js
81 | import React from "react";
82 |
83 | function Example(props) {
84 | const showContent = props.showContent;
85 |
86 | return (
87 |
88 | {showContent ? "This content is visible" : "This content is not visible"}
89 |
90 | );
91 | }
92 | ```
93 |
94 | In this example, the JSX expression will evaluate the showContent prop and render the appropriate content based on its value.
95 |
--------------------------------------------------------------------------------
/Blogs/10.DebuggingWays.md:
--------------------------------------------------------------------------------
1 | # The Art of Debugging in React: A Deep Dive into Best Practices and Common Pitfalls
2 |
3 | > If you're new to debugging in React, you might be wondering how to find and fix errors in your code. Or, if you're an experienced developer, you might be looking for ways to improve your debugging skills. Either way, this post is for you. We'll cover everything you need to know about debugging in React, from the basics to advanced techniques and best practices. By the end of this post, you'll be a pro at debugging your React apps.
4 |
5 | There are a few different tools and techniques you can use to debug and find errors
6 |
7 | ## These are the ways to add start Debugging
8 |
9 | 1. **JavaScript console**: You can use the JavaScript console in your web browser's developer tools to view error messages and log statements from your React code. To open the console in most web browsers, you can use the keyboard shortcut Ctrl + Shift + J (Windows) or Command + Option + J (Mac).
10 |
11 | 2. **React Developer Tools**: You can use the React Developer Tools browser extension to inspect the React components in your application and see their props and state. This can be helpful for understanding how your application is rendering and finding potential errors.
12 |
13 | 3. **Debugger statement**: You can use the debugger statement in your JavaScript code to pause the execution of your code and open the debugger in your web browser's developer tools. This can be useful for inspecting the state of your application and debugging specific parts of your code.
14 |
15 | 4. **Error boundaries**: You can use error boundaries in your React components to catch and handle errors that occur during rendering. This can help to prevent your application from crashing when an error occurs, and can make it easier to debug the error.
16 |
17 | 5. **Logging**: You can use console.log statements and other logging functions to output information about your application to the console. This can be helpful for understanding how your code is executing and finding potential errors.
18 |
--------------------------------------------------------------------------------
/Blogs/11.ReactFragments.md:
--------------------------------------------------------------------------------
1 |
2 | # Eliminate Unnecessary Wrapper Elements with React Fragments
3 | >React fragments are a way to group a list of children without adding additional DOM nodes. Fragments allow you to return multiple elements from a component's render method without wrapping them in an extra element.
4 |
5 | ### There are two ways you can use fragments in React:
6 |
7 | ## 1. React.fragment
8 |
9 | Using the `React.Fragment` component: You can use the `React.Fragment` component to group a list of children without adding additional DOM nodes. This can be useful if you need to support older versions of React that don't support the JSX fragment syntax `(<>>)`.
10 |
11 | ```js
12 | import React from "react";
13 |
14 | function List(props) {
15 | return (
16 |
17 |
Item 1
18 |
Item 2
19 |
Item 3
20 |
21 | );
22 | }
23 |
24 | function App() {
25 | return ;
26 | }
27 | ```
28 |
29 | ## 2. <>>
30 |
31 | Using the JSX fragment syntax `(<>>)`: In newer versions of React, you can use the JSX fragment syntax `(<>>)` to group a list of children without adding additional DOM nodes. This is a shorter and more concise syntax than using the `React.Fragment` component.
32 |
33 | ```js
34 | import React from "react";
35 |
36 | function List(props) {
37 | return (
38 | <>
39 |
Item 1
40 |
Item 2
41 |
Item 3
42 | >
43 | );
44 | }
45 |
46 | function App() {
47 | return ;
48 | }
49 | ```
50 |
51 | Fragments are useful because they allow you to group a list of children without adding additional DOM nodes, which can make your code more efficient and easier to read.
52 |
--------------------------------------------------------------------------------
/Blogs/12.ReactPortals.md:
--------------------------------------------------------------------------------
1 | # Easily Render Components Anywhere with React Portals
2 |
3 | >React portals are a way to render a React component to a different DOM element than the parent component. Portals can be useful in a variety of situations, such as:
4 |
5 | - **Modals:** You can use portals to render a modal or pop-up window that is separate from the rest of the page. This can be helpful for maintaining the focus and structure of the main page while displaying a separate piece of content.
6 |
7 | - **Overlays:** You can use portals to render an overlay or overlay element that is separate from the main content of the page. This can be useful for displaying a loading spinner or a message that needs to be displayed over the main content.
8 |
9 | - **DOM manipulation:** You can use portals to manipulate the DOM in a way that is not possible with the standard React rendering model. For example, you can use portals to append elements to the body of the page, or to render elements outside of the root element of your application.
10 |
11 | To use portals in your React application, you can use the ReactDOM.createPortal function. Here's an example of how you might use a portal to render a modal:
12 |
13 | - First Argument is JSX
14 | - Second argument conatins the attachment of element class or id
15 |
16 | ```js
17 | import React from "react";
18 | import ReactDOM from "react-dom";
19 |
20 | function Modal(props) {
21 | return ReactDOM.createPortal(
22 |
42 | );
43 | }
44 | ```
45 |
46 | In this example, the `Modal` component uses the `ReactDOM.createPortal` function to render a modal element to the `document.body` element. When the modal is opened, it is rendered outside of the App component, allowing it to be displayed over the main content of the page.
47 |
--------------------------------------------------------------------------------
/Blogs/13.useRef()Hook.md:
--------------------------------------------------------------------------------
1 |
2 | # Easily Access and Modify DOM Nodes with useRef in React
3 | >In React, a `ref` is a way to access the properties of a DOM element. Refs are created using React's `createRef` function and attached to React elements via the `ref` attribute.
4 |
5 | Here's an example of how you might use a ref to access the value of an input element:
6 |
7 | ```js
8 | import React, { useRef } from "react";
9 |
10 | function InputForm() {
11 | const inputEl = useRef(null);
12 |
13 | const handleSubmit = (event) => {
14 | event.preventDefault();
15 | console.log(inputEl.current.value);
16 | };
17 |
18 | return (
19 |
26 | );
27 | }
28 | ```
29 |
30 | In this example, the `inputEl` `ref` is created using the `useRef` hook and attached to the input element via the `ref` attribute. When the form is submitted, the handleSubmit function is called, and the value of the input element is logged to the console using the `inputEl.current.value` property.
31 |
32 | There are a few reasons why you might want to use refs in your React application:
33 |
34 | - **DOM manipulation:** Refs can be useful for manipulating the DOM directly, such as focusing an input element or getting the value of a form field.
35 |
36 | - **Third-party libraries:** Refs can be useful for interacting with third-party libraries that require direct access to DOM elements.
37 |
38 | - **Performance optimization:** In some cases, using refs can be more performant than using the state or props of a component to manipulate the DOM.
39 |
--------------------------------------------------------------------------------
/Blogs/14.useEffectHook.md:
--------------------------------------------------------------------------------
1 | # Become a Pro at the useEffect Hook with These Advanced Techniques in React
2 |
3 | >`useEffect` is a hook in React that allows you to perform side effects in function components. It is called after the component renders, and it takes a callback function as an argument. The callback function can be used to perform tasks such as making API calls, setting up event listeners, or updating the DOM.
4 |
5 | One of the main benefits of using `useEffect` is that it helps you manage side effects in a declarative way, rather than using imperative code. This can make your code easier to understand and debug.
6 |
7 | Here's an example of how you can use `useEffect` to make an API call in a React component:
8 |
9 |
10 |
11 | ```js
12 | import { useState, useEffect } from "react";
13 |
14 | function Example() {
15 | const [data, setData] = useState(null);
16 |
17 | useEffect(() => {
18 | async function fetchData() {
19 | const response = await fetch("/some/api/endpoint");
20 | setData(response.data);
21 | }
22 | fetchData();
23 | }, []);
24 |
25 | return
{data &&
Data: {data}
}
;
26 | }
27 | ```
28 |
29 | In this example, the `useEffect` hook is called after the component renders, and it makes an API call to fetch some data. The data is then stored in the data state using the setData function.
30 |
31 | **The second parameter of the useEffect hook** is an array of values that determines when the effect callback function should be called. If the array is empty (as in the example above), the effect callback function is only called after the initial render.
32 |
33 | If you pass an array of values as the second parameter, the effect callback function will be called whenever one of those values changes. For example:
34 |
35 | ```js
36 | import { useState, useEffect } from "react";
37 |
38 | function Example(props) {
39 | const [data, setData] = useState(null);
40 |
41 | useEffect(() => {
42 | async function fetchData() {
43 | const response = await fetch(`/some/api/endpoint/${props.id}`);
44 | setData(response.data);
45 | }
46 | fetchData();
47 | }, [props.id]);
48 |
49 | return
{data &&
Data: {data}
}
;
50 | }
51 | ```
52 |
53 | ## Exceptions and Limitations
54 |
55 | There are a few exceptions to this rule: you do not need to add state updating functions as dependencies, as they are guaranteed to never change. You also do not need to add "built-in" APIs or functions like fetch() or localStorage, as they are independent from React and your components and do not change. Similarly, you do not need to add variables or functions defined outside of your components as dependencies, as changing them will not affect your components.
56 |
57 | It is important to understand these exceptions in order to avoid unnecessary re-evaluations of your side effects, which can improve the performance of your application.
58 |
59 | ## useEffect() cleanup Function
60 |
61 | he cleanup function in useEffect is a callback function that is called just before the effect is unmounted or re-run. This can be useful for performing tasks such as cleaning up event listeners or canceling network requests.
62 |
63 | In general, the cleanup function is called whenever the component that uses useEffect unmounts, or whenever the dependencies of the useEffect hook change and the effect is re-run.
64 |
65 | ```js
66 | import { useState, useEffect } from "react";
67 |
68 | function Example() {
69 | const [data, setData] = useState(null);
70 |
71 | useEffect(() => {
72 | let cancelRequest = false;
73 |
74 | async function fetchData() {
75 | const response = await fetch("/some/api/endpoint");
76 | if (!cancelRequest) {
77 | setData(response.data);
78 | }
79 | }
80 | fetchData();
81 |
82 | return () => {
83 | cancelRequest = true;
84 | };
85 | }, []);
86 |
87 | return
{data &&
Data: {data}
}
;
88 | }
89 | ```
90 |
91 | In this example, the useEffect hook makes an API call to fetch some data. The cancelRequest variable is used to cancel the request if the component unmounts before the request is complete. The cancelRequest variable is set to true in the cleanup function, which is called just before the component unmounts.
92 |
93 | ## Summary
94 |
95 | - Executes after the component renders.
96 | - If no second parameter is specified, the effect function always executes when the component renders.
97 | - If a second parameter is specified and it is an empty array, the effect function only executes the first time the component renders.
98 | - If a second parameter is specified and it is a non-empty array containing mutable values, the effect function only executes when the values in the array change.
99 | - The cleanup function does not execute the first time the component renders.
100 | - The cleanup function executes before the effect function the next time it is called.
101 | - useEffect is helpful for performing tasks like fetching data, sending HTTP requests, and validating forms."
102 |
--------------------------------------------------------------------------------
/Blogs/15.useReducer()Hook.md:
--------------------------------------------------------------------------------
1 | # Effortlessly Manage Complex State with useReducer in React"
2 |
3 | > `useReducer` hook in React. `useReducer` is a hook that allows you to manage state in a functional component. It is similar to the useState hook, but it is more powerful and can be more efficient in certain situations.
4 |
5 | Here is an example of how `useReducer` works:
6 |
7 | ```js
8 | import { useReducer } from "react";
9 |
10 | const initialState = { count: 0 };
11 |
12 | function reducer(state, action) {
13 | switch (action.type) {
14 | case "increment":
15 | return { count: state.count + 1 };
16 | case "decrement":
17 | return { count: state.count - 1 };
18 | default:
19 | throw new Error();
20 | }
21 | }
22 |
23 | function Counter() {
24 | const [state, dispatch] = useReducer(reducer, initialState);
25 | return (
26 | <>
27 | Count: {state.count}
28 |
29 |
30 | >
31 | );
32 | }
33 | ```
34 |
35 | In this example, we have defined a `reducer` function that takes in a state and an action, and returns a new state based on the action type. We have also defined an initial state for our component.
36 |
37 | Next, we use the useReducer hook to create a state variable and a dispatch function. The dispatch function allows us to dispatch actions to the `reducer`, which will update the state based on the action type.
38 |
39 | Finally, we render a counter that displays the current count and has buttons to increment and decrement the count. When the buttons are clicked, we dispatch an action to the reducer to update the state.
40 |
41 | The third parameter of the useReducer hook is an optional argument that allows you to specify an initial state value that is different from the value specified in the reducer function.
42 |
43 | For example:
44 |
45 | ```js
46 | import { useReducer } from "react";
47 |
48 | function reducer(state, action) {
49 | // ...
50 | }
51 |
52 | function MyComponent() {
53 | const initialState = { count: 0 };
54 | const [state, dispatch] = useReducer(
55 | reducer,
56 | initialState,
57 | (initialState) => ({
58 | ...initialState,
59 | count: initialState.count + 10,
60 | })
61 | );
62 | // ...
63 | }
64 | ```
65 |
66 | In this example, the initial state value for the count property is specified as 0 in the reducer function. However, we can use the third parameter of useReducer to specify a different initial value for the count property. In this case, we are using the third parameter to specify that the initial value for the count property should be 10, which is 10 more than the value specified in the reducer function.
67 |
68 | The third parameter of useReducer is a function that takes in the initial state value specified in the reducer function and returns a new initial state value. This can be useful if you want to specify different initial values for different properties, or if you want to perform some other transformation on the initial state value.
69 |
70 | ## Summary
71 |
72 | - Same as the useState just only be used as an alternative for doing the complex logic states , when 2 or more useStates are related to one thing combine them into one useReducer() as an object .
73 |
74 | - disptach() function takes the argument of ypdating state value as an object of the action.
75 |
76 | - reducer function be called when we pass the action value to the dispatch function and this function takes the two parameter of the state which has the previous value and the action value.
77 |
--------------------------------------------------------------------------------
/Blogs/16.comboOFuseEffectAnduseReducer.md:
--------------------------------------------------------------------------------
1 | # "The Perfect Combo: useReducer and useEffect for Powerful React Components"
2 |
3 | >Here is an example of how the useEffect and useReducer hooks can be used together to manage complex state and perform side effects in a React component:
4 |
5 | ```js
6 | import { useEffect, useReducer } from "react";
7 |
8 | const initialState = {
9 | loading: false,
10 | data: [],
11 | error: null,
12 | };
13 |
14 | function reducer(state, action) {
15 | switch (action.type) {
16 | case "LOADING":
17 | return {
18 | loading: true,
19 | data: [],
20 | error: null,
21 | };
22 | case "SUCCESS":
23 | return {
24 | loading: false,
25 | data: action.data,
26 | error: null,
27 | };
28 | case "ERROR":
29 | return {
30 | loading: false,
31 | data: [],
32 | error: action.error,
33 | };
34 | default:
35 | throw new Error("Invalid action type");
36 | }
37 | }
38 |
39 | function MyComponent() {
40 | const [state, dispatch] = useReducer(reducer, initialState);
41 |
42 | useEffect(() => {
43 | dispatch({ type: "LOADING" });
44 |
45 | fetch("https://my-api.com/endpoint")
46 | .then((response) => response.json())
47 | .then((data) => dispatch({ type: "SUCCESS", data }))
48 | .catch((error) => dispatch({ type: "ERROR", error }));
49 | }, []);
50 |
51 | if (state.loading) {
52 | return
Loading...
;
53 | }
54 | if (state.error) {
55 | return
Error: {state.error.message}
;
56 | }
57 | return (
58 |
59 | {state.data.map((item) => (
60 |
{item.name}
61 | ))}
62 |
63 | );
64 | }
65 | ```
66 |
67 | In this example, the useReducer hook is used to manage the loading, data, and error state of a component that is fetching data from an API. The useEffect hook is used to perform the actual fetch request and dispatch actions to the reducer to update the state accordingly. The component will display a loading message while the data is being fetched, an error message if there is an error, or a list of data items if the fetch is successful.
68 |
--------------------------------------------------------------------------------
/Blogs/17.useContext()Hook.md:
--------------------------------------------------------------------------------
1 | # Passing Data through Context API
2 |
3 | > The React Context API allows you to share state and data between components without having to pass props down through multiple levels of the component tree. This can be particularly useful for situations where you have deeply nested components and you want to avoid the prop drilling that would be required to pass the data down through each level.
4 |
5 | ## Why we need the react context API?
6 |
7 | The React Context API is a way to share data that is required by multiple components in a React application, without the need to pass props down through the component tree manually. This can be especially useful for data that is needed by many components, but is not directly related to the rendering of a specific component, such as the currently authenticated user or the current locale.
8 |
9 | Using the Context API can help improve the separation of concerns in a React application, as components do not need to be aware of the specific parent component that is providing the required data. It can also make the component tree more concise, as data that needs to be passed down through multiple levels of components can be provided directly through the context, rather than being passed down as props at each level.
10 |
11 | Overall, the React Context API can be a useful tool for managing data in a React application, particularly when that data is needed by many components and is not directly related to the rendering of specific components.
12 |
13 | # How to use them ?
14 |
15 | To use the Context API, you'll need to create a context object and provide a default value for the context. You can then use the `` component to provide the context value to the components that need it, and the `useContext` hook to consume the context value in those components.
16 |
17 | Here's an example of how you might use the Context API to pass a theme value down to a set of nested components:
18 |
19 | ```js
20 | import React, { createContext, useContext } from "react";
21 |
22 | // Create the context object and specify a default value
23 | const ThemeContext = createContext("light");
24 |
25 | // Create a provider component that will wrap the components that need the context value
26 | const ThemeProvider = ({ value, children }) => (
27 | {children}
28 | );
29 |
30 | // Create a component that consumes the context value
31 | const ThemeButton = () => {
32 | const theme = useContext(ThemeContext);
33 | return ;
34 | };
35 |
36 | // Use the provider component to wrap the component tree and provide the context value
37 | const App = () => (
38 |
39 |
40 |
41 |
42 |
43 | );
44 | ```
45 |
46 | In this example, the ThemeButton component consumes the theme context value and applies it as a classname. The ThemeProvider component provides the context value, which can be changed by updating the value prop of the provider. This allows you to control the theme of the entire component tree by simply changing the value of the context provider at the root level.
47 |
48 | ## Limitation of useContext API
49 |
50 | If you are continously changing the state in every second thean you have not to use the `useContext()`, beacuse it can cause effects to change every component on every seconds.
51 | But if your useContext() data states are changing on after a some time than you hav e must prefer to use them.
52 |
53 | Another limitation of useContext is that it does not support the propagation of context updates to components higher up in the tree. If a context value changes, only the components that directly consume that value using useContext will be re-rendered. This can make it difficult to manage updates to context values that are used by multiple components.
54 |
--------------------------------------------------------------------------------
/Blogs/18.React.memo().md:
--------------------------------------------------------------------------------
1 | # Optimizing Your React Components: A Deep Dive into React's Powerful memo Feature
2 |
3 | > When building React applications, performance is a crucial consideration. One of the biggest performance bottlenecks can be unnecessary re-renders of components, which can lead to slow load times and a poor user experience. Fortunately, React provides a powerful tool to help optimize your components: the `memo` higher order component. In this blog post, we'll take a deep dive into the `memo` feature, exploring how it works and how you can use it to improve the performance of your React applications.
4 |
5 | React `memo` is a higher order component (HOC) that is used to wrap a functional component in order to prevent unnecessary re-renders. It does this by "memoizing" the component, meaning it stores the previous props and state, and only re-renders the component if the props or state have changed.
6 |
7 | Here's an example of how you might use memo to optimize a functional component:
8 |
9 | ```js
10 | import React, { memo } from "react";
11 |
12 | const MyComponent = ({ name, age }) => {
13 | console.log("MyComponent rendered");
14 | return (
15 |
16 | {name} - {age}
17 |
18 | );
19 | };
20 |
21 | export default memo(MyComponent);
22 | ```
23 |
24 | In this example, `MyComponent` is a functional component that takes in `name `and `age` props and renders a div with the `name` and `age`. The `memo` HOC is used to wrap the component, which will prevent it from re-rendering if the `name` and `age` props remain the same.
25 |
26 | In practice, you can see this in action by using the wrapped component multiple times in your application and passing the same props to each instance, you'll see that the wrapped component will only re-render once, as it's memoized.
27 |
28 | You can also pass a custom comparison function as a second argument to `memo` if you want to customize the way the props are compared for changes.
29 |
30 | ```js
31 | export default memo(MyComponent, (prevProps, nextProps) => {
32 | return prevProps.name === nextProps.name && prevProps.age === nextProps.age;
33 | });
34 | ```
35 |
36 | This is only a very basic example, but it illustrates the basic idea behind using `memo` to optimize functional components in React.
37 |
--------------------------------------------------------------------------------
/Blogs/19.useCallback()Hook.md:
--------------------------------------------------------------------------------
1 | # Mastering React Hooks: The useCallback() Function and How to Optimize Your Components
2 |
3 | > React Hooks have revolutionized the way we build React components. One of the most powerful Hooks is the `useCallback()` function, which allows you to optimize your components by only re-creating callbacks when certain dependencies change. In this blog post, we'll explore the `useCallback()` Hook in-depth and learn how it can be used to improve the performance of your React applications. We'll also take a look at some real-world examples of how to use `useCallback()` in your own projects.
4 |
5 | When a component re-renders, React will create a new instance of any functions declared inside the component. This can lead to unnecessary re-renders, especially when the function is passed down as a prop to a child component. The `useCallback()` Hook solves this problem by allowing you to specify which dependencies a callback function depends on, and only re-creating the function when those dependencies change.
6 |
7 | Here's an example of how you might use `useCallback()` in a functional component:
8 |
9 | ```js
10 | import { useCallback } from "react";
11 |
12 | const MyComponent = ({ name }) => {
13 | const handleClick = useCallback(() => {
14 | console.log(`Hello, ${name}!`);
15 | }, [name]);
16 |
17 | return ;
18 | };
19 | ```
20 |
21 | In this example, the `handleClick` function is only re-created when the name prop changes. This means that if the parent component re-renders with the same name prop, the `handleClick` function will not be re-created, and the child component will not re-render.
22 |
23 | You can also use `useCallback()` in conjunction with `memo()` to optimize child components that receive a callback as a prop. Here's an example:
24 |
25 | ```js
26 | import { useCallback } from "react";
27 | import { memo } from "react";
28 |
29 | const ChildComponent = memo(({ callback }) => {
30 | console.log("ChildComponent rendered");
31 | return ;
32 | });
33 |
34 | const ParentComponent = () => {
35 | const handleClick = useCallback(() => {
36 | console.log("Button clicked");
37 | }, []);
38 |
39 | return ;
40 | };
41 | ```
42 |
43 | In this example, the `ChildComponent` is wrapped in the `memo()` HOC, which prevents it from re-rendering unless the callback prop changes. Since the handleClick function is only re-created when the dependencies passed to `useCallback()` change, the `ChildComponent` will only re-render when the dependencies change.
44 |
45 | `useCallback()` is a powerful tool that can help you optimize your React components by preventing unnecessary re-renders. By specifying dependencies and re-creating callbacks only when necessary, you can improve the performance of your applications and provide a better user experience.
46 |
--------------------------------------------------------------------------------
/Blogs/20.StateSecduling.md:
--------------------------------------------------------------------------------
1 | # Navigating the State of React: Understanding and Utilizing State Scheduling
2 |
3 | > Managing state in React can be a tricky task, especially when dealing with complex, multi-step interactions. One of the most recent additions to React's toolset for managing state is state scheduling. State scheduling allows for a more fine-grained control over the timing of state updates, making it easier to handle complex interactions and avoid unexpected behavior. In this blog post, we'll take a closer look at state scheduling in React and explore how it can be used to improve the performance and predictability of your applications.
4 |
5 | State scheduling is a feature in React that allows developers to have more control over when and how state updates are applied. It works by allowing React to "schedule" updates to state, rather than applying them immediately. This allows React to better handle situations where multiple updates need to be made, and to avoid any unexpected issues that might arise when updates are applied in the wrong order.
6 |
7 | State scheduling was introduced as a part of the React concurrent mode, which allows React to schedule updates and render multiple components at the same time.
8 |
9 | One of the most common use cases for state scheduling is handling complex interactions, such as form submissions or animations. Here's an example of how state scheduling can be used to handle a form submission:
10 |
11 | ```js
12 | import { useState, useCallback } from "react";
13 |
14 | const Form = () => {
15 | const [submitting, setSubmitting] = useState(false);
16 | const [formData, setFormData] = useState({});
17 |
18 | const handleSubmit = useCallback(() => {
19 | setSubmitting(true);
20 | setFormData({});
21 | // simulate an async submit
22 | setTimeout(() => {
23 | setSubmitting(false);
24 | }, 2000);
25 | }, []);
26 |
27 | return (
28 |
38 | );
39 | };
40 | ```
41 |
42 | In this example, the handleSubmit function is called when the form is submitted. The first thing it does is set the submitting state to true, which disables the submit button to prevent multiple submissions. Next, it clears the form data by setting it to an empty object. Finally, it simulates an async submit by using setTimeout and sets the submitting state to false after 2 seconds.
43 |
44 | As you can see, the state updates are scheduled by React, so it knows that it should wait to apply the submitting state update until the formData state update has been applied. This prevents any unexpected issues that might arise if the submitting state update were applied first, such as the form data being lost before it could be submitted.
45 |
46 | State scheduling can also be used to optimize performance by allowing React to batch updates together, and apply them all at once. This can be particularly beneficial when dealing with large lists or complex animations.
47 |
48 | In summary, state scheduling is a powerful feature in React that allows developers to have more control over when and how state updates are applied. By using state scheduling, developers can handle complex interactions more easily and avoid unexpected issues that might arise when updates are applied in the wrong order.
49 |
--------------------------------------------------------------------------------
/Blogs/21.useMemo()Hook.md:
--------------------------------------------------------------------------------
1 | # Streamlining Your React Components: A Deep Dive into useMemo Hook
2 |
3 | > Performance optimization is a crucial aspect of building React applications, and one of the most effective ways to achieve this is by avoiding unnecessary re-renders. The `useMemo` hook is a powerful tool that allows you to optimize your functional components by only re-computing expensive calculations when specific dependencies change. In this blog post, we'll take a deep dive into the `useMemo` hook, exploring how it works and how you can use it to improve the performance of your React applications.
4 |
5 | The `useMemo` hook is a powerful tool that allows you to optimize your functional components by only re-computing expensive calculations when specific dependencies change. It works by "memoizing" the calculation and returning the cached result if the dependencies have not changed. This can greatly improve the performance of your application, especially when dealing with complex calculations or large data sets.
6 |
7 | Here's an example of how you might use `useMemo` to memoize a calculation:
8 |
9 | ```js
10 | import { useMemo } from "react";
11 |
12 | const MyComponent = ({ data }) => {
13 | const memoizedData = useMemo(() => {
14 | // expensive calculation
15 | return data.filter((item) => item.active);
16 | }, [data]);
17 |
18 | return (
19 |
20 | {memoizedData.map((item) => (
21 |
{item.name}
22 | ))}
23 |
24 | );
25 | };
26 | ```
27 |
28 | In this example, `MyComponent` takes in an array of `data` and uses the `useMemo` hook to filter the active items from the `data` array. The hook takes in two arguments, the first is a function that returns the memoized value (in this case the filtered `data`) and the second is an array of dependencies, in this case it's the `data` prop.
29 |
30 | Now, whenever `MyComponent` re-renders and the `data` prop does not change, the `useMemo` hook will return the previously memoized `data`, avoiding the expensive calculation and increasing the performance of the component.
31 |
32 | It's important to note that `useMemo` is similar to React.memo, but the main difference is that `useMemo` is used inside a component to memoize a single value while `React.memo` is used outside of a component to wrap it and prevent unnecessary re-renders.
33 |
34 | In summary, `useMemo` is a powerful hook that allows you to optimize your functional components by memoizing expensive calculations and avoiding unnecessary re-computations when specific dependencies have not changed. By using `useMemo` in your application, you can improve the performance of your components and provide a better user experience.
35 |
--------------------------------------------------------------------------------
/Blogs/23.CustomHooks.md:
--------------------------------------------------------------------------------
1 | # Custom Hooks in React: A Game Changer for Your Components
2 |
3 | **Are you tired of writing repetitive code for your React components? Do you want to make your codebase more organized and easy to understand? Look no further than the magic of Custom Hooks!**
4 |
5 | > `Custom Hooks` in `React` simplify code organization and maintenance by allowing the reuse of stateful logic and behavior. They also serve as an alternative to `HOCs` and Render `Props` for simpler and more readable code.
6 |
7 | ```js
8 |
9 | //Custom Hook
10 | import { useState } from 'react';
11 |
12 | function useCounter() {
13 | const [count, setCount] = useState(0);
14 |
15 | function increment() {
16 | setCount(count + 1);
17 | }
18 |
19 | function decrement() {
20 | setCount(count - 1);
21 | }
22 |
23 | return { count, increment, decrement };
24 | }
25 |
26 | export default useCounter;
27 |
28 | ```
29 | This custom hook can be used in a component like this:
30 |
31 |
32 | ```js
33 | import React from 'react';
34 | import useCounter from './useCounter';
35 |
36 | function Counter() {
37 | const { count, increment, decrement } = useCounter();
38 |
39 | return (
40 |
41 |
{count}
42 |
43 |
44 |
45 | );
46 | }
47 |
48 | export default Counter;
49 |
50 | ```
51 | In this example, the `component Counter` is using the custom hook `useCounter` to manage its internal state of count and its increment and decrement functions. It also use the state in its `JSX` to render the count on the screen, and using the **increment and decrement functions** to update the `state`` when the respective buttons are clicked.
52 |
53 |
54 | Here are some tips and rules for creating custom hooks:
55 |
56 | - Follow `use` naming convention for `custom hooks`.
57 | - Only call `custom hook` at top level of component.
58 | - Do not use inside `loops` or `conditions`.
59 | - Make hook reusable by using props passed as arguments.
60 | - Test and document the custom hook with usage instructions.
--------------------------------------------------------------------------------
/Blogs/ReactForms.md:
--------------------------------------------------------------------------------
1 | # React Form Pro-Tips: Level Up Your Skills
2 |
3 | > `React` is a game-changer when it comes to building `user interfaces`, and one of its most powerful features is the ability to handle forms and user input like a pro! In this blog, we're going to explore some of the best practices, techniques, and pro-tips for working with forms in React, so that you can take your skills to the next level and build more efficient and user-friendly applications.
4 |
5 | First and foremost, it's crucial to understand the concept of `controlled components` when working with forms in `React`. Controlled components are components that keep the state of the form in the parent component, rather than in the individual form elements. This allows for better handling of form **validation** and **submission**, and makes it easy to access and update the form data in the `parent component`
6 |
7 |
8 | Are you ready to level up your form game in `React`? Let's explore the different strategies for **form validation** and pick the perfect one for your project!
9 |
10 | First up, we have the `submit and validate` approach. This strategy is super simple and easy to implement, it only shows error messages when the user is ready to submit the form. It's a classic, **no-nonsense approach** that gets the job done.
11 |
12 | ```js
13 | const handleSubmit = event => {
14 | event.preventDefault();
15 | const errors = validateForm();
16 | setErrors(errors);
17 | if (!Object.keys(errors).length) {
18 | //submit the formData
19 | }
20 | };
21 |
22 | ```
23 |
24 | Next, we have the ``validate on blur`` approach. This strategy provides **instant feedback** to the user and catches `errors` as they happen. It's like having a personal form coach, always there to catch your mistakes!
25 | ```js
26 | const handleBlur = event => {
27 | const { name } = event.target;
28 | const error = validate(name, formData[name]);
29 | setErrors({ ...errors, [name]: error });
30 | };
31 |
32 | ```
33 |
34 | And finally, we have the `validate on every stroke` approach. This strategy is the most responsive and provides the most **immediate feedback**, but it can also be the **most annoying** for the user. It's like having a form drill sergeant, pushing you to be your best!
35 | ```js
36 | const handleChange = event => {
37 | const { name, value } = event.target;
38 | const error = validate(name, value);
39 | setErrors({ ...errors, [name]: error });
40 | setFormData({ ...formData, [name]: value });
41 | };
42 |
43 | ```
44 |
45 | So, which approach is the best for your project? It all depends on your **specific requirements**. Do you want to provide instant feedback and catch errors early on? Go for the `validate on blur` approach. Do you want to be super responsive and provide the most immediate feedback? Go for the `validate on every stroke` approach. Whichever strategy you choose, make sure to test it thoroughly and provide a great user experience!
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Blogs/ReactRouter.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Blogs/ReactRouter.md
--------------------------------------------------------------------------------
/EssentailCommands.md:
--------------------------------------------------------------------------------
1 | # Some useful Commands
2 |
3 | ## To use the different node versions.
4 |
5 | ```sh
6 | nvm install 12.18.3
7 | nvm use 12.18.3
8 | ```
9 |
10 | ## To start the react-app
11 |
12 | ```sh
13 | npm init react-app my-app
14 | cd my-app
15 | npm start
16 | ```
17 |
18 | To end the react app `Ctrl+c `(In linux)
19 |
20 | ## To install the all dependencies in the package.json
21 |
22 | ```sh
23 | npm install
24 | ```
25 |
26 | ## To install the styled-components library
27 |
28 | ```sh
29 | npm i --save -styled-components
30 | ```
31 |
32 | ## To production build react app on your PC
33 |
34 | ```sh
35 | npm install -g serve
36 | serve -s build
37 | ```
38 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Muhib Arshad
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Projects/AddUser/Screenshot from 2023-01-01 01-51-23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/AddUser/Screenshot from 2023-01-01 01-51-23.png
--------------------------------------------------------------------------------
/Projects/AddUser/build/asset-manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "files": {
3 | "main.css": "/static/css/main.dce1127a.chunk.css",
4 | "main.js": "/static/js/main.6377feb0.chunk.js",
5 | "main.js.map": "/static/js/main.6377feb0.chunk.js.map",
6 | "runtime-main.js": "/static/js/runtime-main.36ce5d8f.js",
7 | "runtime-main.js.map": "/static/js/runtime-main.36ce5d8f.js.map",
8 | "static/js/2.14e73586.chunk.js": "/static/js/2.14e73586.chunk.js",
9 | "static/js/2.14e73586.chunk.js.map": "/static/js/2.14e73586.chunk.js.map",
10 | "index.html": "/index.html",
11 | "static/css/main.dce1127a.chunk.css.map": "/static/css/main.dce1127a.chunk.css.map",
12 | "static/js/2.14e73586.chunk.js.LICENSE.txt": "/static/js/2.14e73586.chunk.js.LICENSE.txt"
13 | },
14 | "entrypoints": [
15 | "static/js/runtime-main.36ce5d8f.js",
16 | "static/js/2.14e73586.chunk.js",
17 | "static/css/main.dce1127a.chunk.css",
18 | "static/js/main.6377feb0.chunk.js"
19 | ]
20 | }
--------------------------------------------------------------------------------
/Projects/AddUser/build/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/AddUser/build/favicon.ico
--------------------------------------------------------------------------------
/Projects/AddUser/build/index.html:
--------------------------------------------------------------------------------
1 | React App
--------------------------------------------------------------------------------
/Projects/AddUser/build/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/AddUser/build/logo192.png
--------------------------------------------------------------------------------
/Projects/AddUser/build/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/AddUser/build/logo512.png
--------------------------------------------------------------------------------
/Projects/AddUser/build/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/Projects/AddUser/build/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/Projects/AddUser/build/static/css/main.dce1127a.chunk.css:
--------------------------------------------------------------------------------
1 | *{box-sizing:border-box}html{font-family:sans-serif}body{margin:0}.AddUserForm_form__jJc2d{display:flex;flex-direction:column;align-items:center;width:50%;margin:100px auto;padding:20px;border:1px solid #d3d3d3;border-radius:10px}.AddUserForm_input__1kDxm input{width:80%;height:40px;margin:10px 0;padding:0 10px;border:1px solid #d3d3d3;border-radius:5px;font-size:16px}.AddUserForm_button__s31hG{width:80%;height:50px;margin:20px 0;padding:0 10px;border:none;border-radius:5px;background-color:#6495ed;color:#fff;font-size:18px;cursor:pointer}.AddUserForm_button__s31hG:hover{background-color:#4169e1}.ModelWindow_modal-backdrop__ev6o-{position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,.5);z-index:10}.ModelWindow_modal-window__14m86{position:fixed;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);width:400px;max-height:80%;overflow-y:auto;background-color:#fff;box-shadow:0 0 10px rgba(0,0,0,.5);z-index:20}.ModelWindow_modal-header__2IBEH{display:flex;align-items:center;justify-content:space-between;padding:20px;border-bottom:1px solid #ddd}.ModelWindow_modal-header__2IBEH h2{font-size:22px;font-weight:700;margin:0}.ModelWindow_modal-header__2IBEH .ModelWindow_close-button__1ZAd7{font-size:20px;font-weight:700;text-decoration:none;color:#999}.ModelWindow_modal-header__2IBEH .ModelWindow_close-button__1ZAd7:hover{color:#333}.ModelWindow_modal-body__20OAk{padding:20px}.ModelWindow_modal-body__20OAk p{font-size:16px;margin:0}.ModelWindow_modal-body__20OAk .ModelWindow_error-message__3qozT{color:red}.ModelWindow_button__a2RwR{display:block;margin:20px auto;padding:10px 20px;border:none;border-radius:5px;background-color:#333;color:#fff;font-size:16px;cursor:pointer}.ModelWindow_button__a2RwR:hover{background-color:#555}.UserInfo_user-info__1bzWu{display:flex;flex-direction:column;align-items:center;background-color:#e6e6e6;padding:20px;border-radius:10px;width:700px;margin:20px auto}.UserInfo_user-info__1bzWu p{font-size:18px;font-weight:700;margin:10px 0}.UserInfo_user-info__1bzWu p.UserInfo_label__3oKnU{color:#777}.UserInfo_delete__nsCVZ{display:block;margin:10px 0;padding:5px 10px;border:none;border-radius:10px;background-color:#f44336;color:#fff;font-size:14px;height:4vh;width:10vh;cursor:pointer}.UserInfo_delete__nsCVZ:hover{background-color:#dc3545}.UserInfo_update-button__ux-VA{background-color:#3498db;border:none;color:#fff;padding:15px 32px;text-align:center;text-decoration:none;display:inline-block;font-size:16px;margin:4px 2px;cursor:pointer;border-radius:10px}.UpdateWindow_modal-container__3CVg5{position:fixed;top:0;left:0;width:100%;height:100%;z-index:1000;display:flex;align-items:center;justify-content:center}.UpdateWindow_modal-backdrop__37CdS{position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,.5);z-index:999}.UpdateWindow_modal-content__1vn5S{background-color:#fff;border-radius:5px;box-shadow:0 0 10px rgba(0,0,0,.2);padding:20px;width:500px;z-index:1000}form{display:flex;flex-direction:column}label{margin-bottom:5px}input,label{font-size:14px}input{border:1px solid #ccc;border-radius:4px;padding:8px;width:100%}.UpdateWindow_update-button__2r-PT{background-color:#3498db;border:none;color:#fff;padding:15px 32px;text-align:center;text-decoration:none;display:inline-block;font-size:20px;cursor:pointer}.UpdateWindow_update-button__2r-PT :hover{background-color:#2980b9}.App_App__16ZpL{height:200vh;text-align:center}.App_delete-all__3WDz6{display:block;margin:50px 450px;padding:10px 20px;border:none;border-radius:5px;background-color:#f44336;color:#fff;font-size:16px;cursor:pointer}.App_delete-all__3WDz6:hover{background-color:#dc3545}
2 | /*# sourceMappingURL=main.dce1127a.chunk.css.map */
--------------------------------------------------------------------------------
/Projects/AddUser/build/static/js/2.14e73586.chunk.js.LICENSE.txt:
--------------------------------------------------------------------------------
1 | /*
2 | object-assign
3 | (c) Sindre Sorhus
4 | @license MIT
5 | */
6 |
7 | /** @license React v0.20.2
8 | * scheduler.production.min.js
9 | *
10 | * Copyright (c) Facebook, Inc. and its affiliates.
11 | *
12 | * This source code is licensed under the MIT license found in the
13 | * LICENSE file in the root directory of this source tree.
14 | */
15 |
16 | /** @license React v17.0.2
17 | * react-dom.production.min.js
18 | *
19 | * Copyright (c) Facebook, Inc. and its affiliates.
20 | *
21 | * This source code is licensed under the MIT license found in the
22 | * LICENSE file in the root directory of this source tree.
23 | */
24 |
25 | /** @license React v17.0.2
26 | * react-jsx-runtime.production.min.js
27 | *
28 | * Copyright (c) Facebook, Inc. and its affiliates.
29 | *
30 | * This source code is licensed under the MIT license found in the
31 | * LICENSE file in the root directory of this source tree.
32 | */
33 |
34 | /** @license React v17.0.2
35 | * react.production.min.js
36 | *
37 | * Copyright (c) Facebook, Inc. and its affiliates.
38 | *
39 | * This source code is licensed under the MIT license found in the
40 | * LICENSE file in the root directory of this source tree.
41 | */
42 |
--------------------------------------------------------------------------------
/Projects/AddUser/build/static/js/runtime-main.36ce5d8f.js:
--------------------------------------------------------------------------------
1 | !function(e){function t(t){for(var n,l,i=t[0],a=t[1],c=t[2],f=0,s=[];f0.2%",
25 | "not dead",
26 | "not op_mini all"
27 | ],
28 | "development": [
29 | "last 1 chrome version",
30 | "last 1 firefox version",
31 | "last 1 safari version"
32 | ]
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Projects/AddUser/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/AddUser/public/favicon.ico
--------------------------------------------------------------------------------
/Projects/AddUser/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/Projects/AddUser/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/AddUser/public/logo192.png
--------------------------------------------------------------------------------
/Projects/AddUser/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/AddUser/public/logo512.png
--------------------------------------------------------------------------------
/Projects/AddUser/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/Projects/AddUser/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/Projects/AddUser/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | # React ADD USER APP (CRUD-Functionality)
7 |
8 | # [Preview Site Here](https://crud-users-app-muhib7353.netlify.app/)
9 | ## I developed this project without the help of an instructor and added all the features myself.
10 | A simple ADD USER built with React.
11 |
12 | ## Features
13 |
14 | - Add user
15 | - Delete user
16 | - Update User
17 | - Read User
18 | - Delete All users
19 | - Input Validations(model-windows on specific errors)
20 | - Data Reterving functionality (LocalStorage)
21 |
22 | ## Getting Started
23 |
24 | To get started, clone the repository and `install` the dependencies:
25 |
26 | ```sh
27 |
28 | git clone https://github.com/muhib7353/React-js-Blogs-and-Projects.git
29 | cd Projects
30 | cd AddUser
31 | npm install
32 | ```
33 |
34 | Then, you can start the development server with the following command:
35 |
36 | ```sh
37 | npm start
38 | ```
39 |
40 | This will start the development server and open the app in your default web browser. The app will automatically reload whenever you make changes to the code.
41 |
42 | ## For Production
43 |
44 | npm run build creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index.html, and requests to static paths like /static/js/main..js are served with the contents of the /static/js/main..js file. For more information see the production build section.
45 |
46 | For environments using Node, the easiest way to handle this would be to install serve and let it handle the rest
47 |
48 | ```sh
49 | npm install -g serve
50 | serve -s build
51 | ```
52 |
--------------------------------------------------------------------------------
/Projects/AddUser/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from "react";
2 | import AddUserForm from "./Components/AddUserForm";
3 | import AddedUser from "./Components/AddedUser";
4 | import * as appStyle from "./App.module.css";
5 | const usersList = [];
6 |
7 | const App = () => {
8 | const [listOfUsers, updatedListOfusers] = useState(() => {
9 | try {
10 | const item = window.localStorage.getItem("users");
11 | return item ? JSON.parse(item) : usersList;
12 | } catch (error) {
13 | console.log(error);
14 | return usersList;
15 | }
16 | });
17 |
18 | const updatedusersHandler = (addedUser) => {
19 | console.log(addedUser);
20 | updatedListOfusers([addedUser, ...listOfUsers]);
21 | };
22 | const onDeleteHandler = (id) => {
23 | const filteredUsers = listOfUsers.filter((user) => user.id !== id);
24 | updatedListOfusers(filteredUsers);
25 | };
26 | const deleteAllHandler = () => {
27 | updatedListOfusers([]);
28 | };
29 |
30 |
31 | const onUpdateHandler = (updatedUser) => {
32 | const updatedUsers = listOfUsers.map((user) => {
33 | if (user.id === updatedUser.id) {
34 | user.name = updatedUser.name;
35 | user.age = updatedUser.age;
36 | }
37 | return user;
38 | });
39 | updatedListOfusers(updatedUsers);
40 | };
41 |
42 |
43 | useEffect(() => {
44 | try {
45 | window.localStorage.setItem("users", JSON.stringify(listOfUsers));
46 | } catch (error) {
47 | // console.log(error);
48 | }
49 | }, [listOfUsers]);
50 | return (
51 |
5 |
6 | # React FOOD ORDERING APP (CRUD-Functionality)
7 |
8 | ## I developed this project without the help of an instructor.
9 | A simple ADD Food to Cart built with React.
10 |
11 | ## Features
12 |
13 | - Add food to cart
14 | - Delete carts
15 | - more add carts
16 | - Read carts
17 | - Input Validations(model-windows on specific errors)
18 |
19 | ## Getting Started
20 |
21 | To get started, clone the repository and `install` the dependencies:
22 |
23 | ```sh
24 |
25 | git clone https://github.com/muhib7353/React-js-Blogs-and-Projects.git
26 | cd Projects
27 | cd Food Ordering App
28 | npm install
29 | ```
30 |
31 | Then, you can start the development server with the following command:
32 |
33 | ```sh
34 | npm start
35 | ```
36 |
37 | This will start the development server and open the app in your default web browser. The app will automatically reload whenever you make changes to the code.
38 |
39 | ## For Production
40 |
41 | npm run build creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index.html, and requests to static paths like /static/js/main..js are served with the contents of the /static/js/main..js file. For more information see the production build section.
42 |
43 | For environments using Node, the easiest way to handle this would be to install serve and let it handle the rest
44 |
45 | ```sh
46 | npm install -g serve
47 | serve -s build
48 | ```
49 |
--------------------------------------------------------------------------------
/Projects/Food Ordering App/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import Cart from "./Components/Cart/Cart";
3 | import Header from "./Components/Layout/Header";
4 | import Meals from "./Components/Meals/Meals";
5 | import CartProvider from "./Store/CartProvider";
6 | function App() {
7 | const [isCartShown, updateCartShown] = useState(false);
8 |
9 | const showCartHandler = () => {
10 | updateCartShown(true);
11 | };
12 | const hideCartHandler = () => {
13 | updateCartShown(false);
14 | };
15 |
16 | return (
17 |
18 | {isCartShown && }
19 |
20 |
21 |
22 |
23 |
24 | );
25 | }
26 |
27 | export default App;
28 |
--------------------------------------------------------------------------------
/Projects/Food Ordering App/src/Assets/meals.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/muhibarshad/React-js-Blogs-and-Projects/23d05834f2edb91bb4d3750b25826240705e936e/Projects/Food Ordering App/src/Assets/meals.jpg
--------------------------------------------------------------------------------
/Projects/Food Ordering App/src/Components/Cart/Cart.js:
--------------------------------------------------------------------------------
1 | import { useContext } from "react";
2 | import cartContext from "../../Store/cart-context";
3 | import Model from "../UI/Model";
4 | import * as cartStyle from "./Cart.module.css";
5 | import CartItem from "./CartItem";
6 |
7 | const Cart = (props) => {
8 | const ctx = useContext(cartContext);
9 | const itemsLength = ctx.item.length > 0;
10 | const totalAmount = `$ ${ctx.totalAmount.toFixed(2)}`;
11 | const onRemoveHandler = (id) => {
12 | ctx.removeItem(id);
13 | };
14 | const onAddHandler = (item) => {
15 | ctx.addItem({ ...item, amount: 1 });
16 | };
17 | const cartItems = (
18 |