ReactJS Learning Plan
ReactJS Learning Plan
js Learning Plan
Day 1-2: Introduction to React
- What is React? React is a JavaScript library for building user interfaces, primarily for single-page
- React Setup: Use 'Create React App' to set up a new project quickly. Install using npm or yarn.
- React Components: Components are the building blocks of React apps. There are two types: Functional
- JSX: JavaScript XML, a syntax extension that allows mixing HTML with JavaScript.
Example:
```
function HelloWorld() {
```
- Props: Props (short for properties) are used to pass data from one component to another.
- State: State is used to store information that may change over time in a component.
- Event Handling: React allows you to handle user events (like clicks) via synthetic events.
Example:
```
```
Day 4: Conditional Rendering and Lists
- Conditional Rendering: Use JavaScript conditions to render elements based on some logic.
- Lists: You can render lists dynamically using the array `map()` function.
- Keys: Keys help React identify which items have changed or are removed.
Example:
```
return (
<ul>
</ul>
);
```
- Controlled Components: Form inputs where React controls the value via state.
- Managing Form State: Use `useState` hook to manage the value of form elements.
Example:
```
function Form() {
return (
<form>
<input value={name} onChange={(e) => setName(e.target.value)} />
</form>
);
```
- Hooks: Hooks like `useState` and `useEffect` provide a functional alternative to lifecycle methods.
Example:
```
useEffect(() => {
}, [name]);
```
- `useEffect`: Hook for side effects like fetching data or manually changing the DOM.
Example:
```
function useCounter() {
```
Example:
```
```
- Lifting State: When two components need to share state, the state should be lifted up to their closest
common ancestor.
- Context API: Avoid prop drilling by providing global state through the React context.
Example:
```
function ThemeButton() {
```
Day 11: Managing Side Effects
- Side Effects: Use `useEffect` for data fetching, subscriptions, or manually changing the DOM.
- Asynchronous Operations: Handle async tasks like fetching data from APIs with `fetch()` or `axios`.
Example:
```
useEffect(() => {
setData(await res.json());
fetchData();
}, []);
```
- Higher-order Components (HOC): A function that takes a component and returns a new component.
- Render Props: A technique for sharing code between components using a prop whose value is a
function.
Example:
```
function withAuth(Component) {
```
- Testing: Write tests to verify component behavior using libraries like Jest and React Testing Library.
Example:
```
render(<App />);
expect(linkElement).toBeInTheDocument();
});
```
Example:
```
```