Skip to content

Commit ffc52f5

Browse files
authored
Merge pull request #7 from anjali-vaish/feat/complete-react-notes
Added remaining notes for ReactJS and updated readme
2 parents 2adb0cd + 945206c commit ffc52f5

File tree

7 files changed

+869
-7
lines changed

7 files changed

+869
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ Site Reference: <https://www.framer.com/motion/introduction/>
5555
## React JS
5656

5757
- [React JS Documentation](ReactJS/ReactJS-Documentation.md)
58-
- [React JS Components](ReactJS/ReactJS-Components.md) //TODO:
58+
- [React JS Components](ReactJS/ReactJS-Components.md)
5959
- [React JS Hooks](ReactJS/ReactJS-Hooks.md)
60-
- [React JS Styling](ReactJS/ReactJS-Styling.md) //TODO:
61-
- [React JS Forms](ReactJS/ReactJS-Forms.md) //TODO:
62-
- [React JS Routing](ReactJS/ReactJS-Routing.md) //TODO:
60+
- [React JS Styling](ReactJS/ReactJS-Styling.md)
61+
- [React JS Forms](ReactJS/ReactJS-Forms.md)
62+
- [React JS Routing](ReactJS/ReactJS-Routing.md)
6363
- [React JS Query](ReactJS/ReactJS-Query.md)
6464
- [React JS State](ReactJS/ReactJS-useState.md)
6565
- [React JS UseEffect](ReactJS/ReactJS-useEffect.md)
6666
- [React JS Use Context](ReactJS/ReactJS-useContext.md)
67-
- [React JS State Management](ReactJS/ReactJS-State-Management.md) //TODO:
68-
- [React JS Testing](ReactJS/ReactJS-Testing.md) //TODO:
69-
- [React JS Deployment](ReactJS/ReactJS-Deployment.md) //TODO:
67+
- [React JS State Management](ReactJS/ReactJS-State-Management.md)
68+
- [React JS Testing](ReactJS/ReactJS-Testing.md)
69+
- [React JS Deployment](ReactJS/ReactJS-Deployment.md)
7070

7171
## Next JS //TODO: update
7272

ReactJS/deployment.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# React JS Deployment
2+
3+
Deploying React applications efficiently is crucial for delivering your project to users. This guide covers various deployment strategies and platforms, ensuring you can choose and utilize the best option for your needs.
4+
5+
## Table of Contents
6+
7+
- [Introduction to Deployment in React](#introduction-to-deployment-in-react)
8+
- [Preparing Your Application for Deployment](#preparing-your-application-for-deployment)
9+
- [Deployment with Vercel](#deployment-with-vercel)
10+
- [Deployment with Netlify](#deployment-with-netlify)
11+
- [Deployment with AWS Amplify](#deployment-with-aws-amplify)
12+
- [Best Practices](#best-practices)
13+
14+
---
15+
16+
## Introduction to Deployment in React
17+
18+
Deploying a React application involves packaging up your application into static files that can be served over the web. Understanding the deployment process and options can help you make informed choices about how to proceed.
19+
20+
## Preparing Your Application for Deployment
21+
22+
Before deploying, ensure your application is production-ready:
23+
24+
1. **Optimize Performance**: Minify CSS and JavaScript files, and use tools like Webpack or Rollup for bundling.
25+
2. **Environment Variables**: Separate your development-specific configurations from production via environment variables.
26+
3. **Testing**: Ensure your application passes all tests and works as expected.
27+
4. **Build**: Run the build command to create a production build of your app:
28+
29+
```bash
30+
npm run build
31+
```
32+
33+
This command will create a `build` directory with all the optimized production files.
34+
35+
## Deployment with Vercel
36+
37+
Vercel is a cloud platform for static sites and Serverless Functions that provides a seamless way to deploy React applications.
38+
39+
**Steps:**
40+
41+
1. Sign up or log in to [Vercel](https://vercel.com).
42+
2. Connect your GitHub, GitLab, or Bitbucket repository.
43+
3. Import your React project.
44+
4. Configure build settings if necessary (Vercel usually auto-detects React projects).
45+
5. Deploy your application. Vercel handles the rest, providing a URL to access your deployed site.
46+
47+
## Deployment with Netlify
48+
49+
Netlify offers CI/CD, serverless backend services, and hosting for static sites.
50+
51+
**Steps:**
52+
53+
1. Sign up or log in to [Netlify](https://netlify.com).
54+
2. Click "New site from Git".
55+
3. Select your repository provider and choose your repository.
56+
4. Set the build command to `npm run build` and the publish directory to `build/`.
57+
5. Deploy your site. Netlify provides a URL and options for custom domains.
58+
59+
## Deployment with AWS Amplify
60+
61+
AWS Amplify provides hosting for static websites with continuous deployment from your Git repository.
62+
63+
**Steps:**
64+
65+
1. Sign up or log into the [AWS Management Console](https://aws.amazon.com).
66+
2. Navigate to AWS Amplify.
67+
3. Connect your repository and branch.
68+
4. Configure the build settings using the `amplify.yml` file or the default configuration.
69+
5. Deploy your application. Amplify will build and deploy your app and provide a URL to access it.
70+
71+
## Best Practices
72+
73+
- **Continuous Deployment**: Set up continuous deployment from your repository to automatically build and deploy your application when you push changes.
74+
- **SSL Certificates**: Ensure HTTPS to secure your application and gain trust from users.
75+
- **Cache Control**: Configure caching strategies for static assets to improve load times.
76+
- **Monitor and Optimize**: Use monitoring tools to track your application's performance and optimize based on the data you collect.
77+
78+
[EOF]
79+
```

ReactJS/forms.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# React JS Forms
2+
3+
Handling forms in React is an essential skill for building interactive web applications. This guide will explore different methods to manage form state and handle form submission, including controlled components, uncontrolled components, and libraries like Formik.
4+
5+
## Table of Contents
6+
7+
- [Introduction to React Forms](#introduction-to-react-forms)
8+
- [Controlled Components](#controlled-components)
9+
- [Uncontrolled Components](#uncontrolled-components)
10+
- [Using Formik](#using-formik)
11+
- [Validation Techniques](#validation-techniques)
12+
- [Best Practices](#best-practices)
13+
14+
---
15+
16+
## Introduction to React Forms
17+
18+
Forms in React can manage input from the user, which is often necessary for tasks like login, registration, and data entry.
19+
20+
## Controlled Components
21+
22+
Controlled components are those where React controls the form data. In these components, form data is handled by the state within the component.
23+
24+
**Example:**
25+
26+
```jsx
27+
import React, { useState } from 'react';
28+
29+
const Form = () => {
30+
const [inputValue, setInputValue] = useState('');
31+
32+
const handleChange = (event) => {
33+
setInputValue(event.target.value);
34+
};
35+
36+
const handleSubmit = (event) => {
37+
event.preventDefault();
38+
alert('A name was submitted: ' + inputValue);
39+
};
40+
41+
return (
42+
<form onSubmit={handleSubmit}>
43+
<label>
44+
Name:
45+
<input type="text" value={inputValue} onChange={handleChange} />
46+
</label>
47+
<button type="submit">Submit</button>
48+
</form>
49+
);
50+
};
51+
```
52+
53+
In this example, the form is controlled via state. Every state mutation will have an associated handler function.
54+
55+
## Uncontrolled Components
56+
57+
Uncontrolled components are those where form data is handled by the DOM itself. React does not control the state of the inputs.
58+
59+
**Example:**
60+
61+
```jsx
62+
import React, { useRef } from 'react';
63+
64+
const Form = () => {
65+
const inputRef = useRef();
66+
67+
const handleSubmit = (event) => {
68+
event.preventDefault();
69+
alert('A name was submitted: ' + inputRef.current.value);
70+
};
71+
72+
return (
73+
<form onSubmit={handleSubmit}>
74+
<label>
75+
Name:
76+
<input type="text" ref={inputRef} />
77+
</label>
78+
<button type="submit">Submit</button>
79+
</form>
80+
);
81+
};
82+
```
83+
84+
This form uses `useRef` to access the DOM node directly, which is typical for uncontrolled components.
85+
86+
## Using Formik
87+
88+
Formik is a popular library to help manage form state, validation, and submission in React.
89+
90+
**Example:**
91+
92+
```jsx
93+
import React from 'react';
94+
import { useFormik } from 'formik';
95+
96+
const Form = () => {
97+
const formik = useFormik({
98+
initialValues: {
99+
name: '',
100+
},
101+
onSubmit: values => {
102+
alert('A name was submitted: ' + values.name);
103+
},
104+
});
105+
106+
return (
107+
<form onSubmit={formik.handleSubmit}>
108+
<label>
109+
Name:
110+
<input
111+
type="text"
112+
name="name"
113+
onChange={formik.handleChange}
114+
value={formik.values.name}
115+
/>
116+
</label>
117+
<button type="submit">Submit</button>
118+
</form>
119+
);
120+
};
121+
```
122+
123+
Formik simplifies the form handling by taking care of the repetitive and complex parts of form state management and validation.
124+
125+
## Validation Techniques
126+
127+
Validating form input is crucial to maintaining data integrity.
128+
129+
**Example using Formik with Yup:**
130+
131+
```jsx
132+
import React from 'react';
133+
import { useFormik } from 'formik';
134+
import * as Yup from 'yup';
135+
136+
const validationSchema = Yup.object({
137+
name: Yup.string()
138+
.required('Required')
139+
.min(2, 'Too Short!'),
140+
});
141+
142+
const Form = () => {
143+
const formik = useFormik({
144+
initialValues: {
145+
name: '',
146+
},
147+
validationSchema,
148+
onSubmit: values => {
149+
alert('Form Submitted');
150+
},
151+
});
152+
153+
return (
154+
<form onSubmit={formik.handleSubmit}>
155+
<label>
156+
Name:
157+
<input
158+
type="text"
159+
name="name"
160+
onChange={formik.handleChange}
161+
onBlur={formik.handleBlur}
162+
value={formik.values.name}
163+
/>
164+
{formik.touched.name && formik.errors.name ? (
165+
<div>{formik.errors.name}</div>
166+
) : null}
167+
</label>
168+
<button type="submit">Submit</button>
169+
</form>
170+
);
171+
};
172+
```
173+
174+
This example integrates Yup for schema validation, providing error messages and form validation rules.
175+
176+
## Best Practices
177+
178+
- **Use Controlled Components for Predictable State**: Controlled components are easier to debug and integrate with complex UIs.
179+
- **Use Uncontrolled Components for Simplicity and Performance**: When you need simple forms without complex interactions.
180+
- **Leverage Libraries like Formik**: These libraries simplify form handling and validation.
181+
- **Always Validate User Input**: To ensure data integrity and user feedback.
182+
183+
[EOF]
184+
```

0 commit comments

Comments
 (0)