Skip to content

Commit 0e97f63

Browse files
committed
chore(use-state): add slides until useState hook
1 parent 4520022 commit 0e97f63

File tree

13 files changed

+1198
-1566
lines changed

13 files changed

+1198
-1566
lines changed
79.2 KB
Loading
125 KB
Loading
107 KB
Loading
184 KB
Loading
279 KB
Loading
125 KB
Loading

content/styling-options.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
## Styling options in React
2+
3+
--
4+
5+
In React, there are multiple ways to apply styles, each with its advantages. Whether you're applying styles directly within your JSX or using sophisticated libraries, React makes it flexible to suit your project's needs.
6+
7+
8+
---
9+
10+
#### Introduction to Styling in React
11+
12+
- Inline Styling <!-- .element class="fragment" -->
13+
- CSS Modules <!-- .element class="fragment" -->
14+
- Styling Libraries <!-- .element class="fragment" -->
15+
- Styled Components <!-- .element class="fragment" -->
16+
- Material UI <!-- .element class="fragment" -->
17+
- Tailwind CSS <!-- .element class="fragment" -->
18+
19+
---
20+
21+
#### Inline Styling
22+
23+
- Definition: Applying styles directly within JSX using the style attribute.
24+
- Example:
25+
26+
```jsx []
27+
const Counter = () => {
28+
return <div style={{
29+
margin: 10,
30+
padding: 20,
31+
border: '1px solid red'
32+
}}>
33+
Hello, counter
34+
</div>
35+
}
36+
```
37+
--
38+
39+
#### Inline Styling
40+
41+
Pros and Cons:
42+
- Quick and easy for simple styles
43+
- Limited scalability and reusability
44+
45+
---
46+
47+
#### CSS Modules
48+
49+
- Definition: A CSS file in which all class names and animation names are scoped locally by default.
50+
- Code example:
51+
52+
```css []
53+
/* Button.module.css */
54+
.myButton {
55+
padding: 10px 15px;
56+
border: none;
57+
background-color: blue;
58+
color: white;
59+
border-radius: 5px;
60+
}
61+
```
62+
<!-- .element: style="font-size: 1rem;" -->
63+
64+
```jsx []
65+
// Button.jsx
66+
import { FC } from 'react';
67+
import styles from './Button.module.css';
68+
const ButtonProps = {
69+
text: string;
70+
}
71+
const Button: FC<ButtonProps> = ({text}) => {
72+
return <button className={styles.myButton}>{text}</button>;
73+
}
74+
```
75+
<!-- .element: style="font-size: 1rem;" -->
76+
77+
--
78+
## CSS Modules
79+
80+
Pros and Cons:
81+
- Scoped styles prevent conflicts
82+
- More maintainable than inline styles
83+
84+
---
85+
86+
## Styling Libraries
87+
88+
--
89+
90+
#### Styled Components
91+
92+
- Utilize tagged template literals to style your components
93+
- Code example:
94+
95+
```jsx []
96+
import styled from 'styled-components';
97+
import { FC } from 'react';
98+
99+
const ButtonProps = {
100+
text: string;
101+
}
102+
const StyledButton = styled.button`
103+
background-color: purple;
104+
color: white;
105+
padding: 8px 12px;
106+
border-radius: 5px;
107+
border: none;
108+
`;
109+
110+
export const Button: FC<ButtonProps> = ({text}) => {
111+
return <StyledButton>{text}</StyledButton>;
112+
}
113+
```
114+
115+
--
116+
117+
#### Material UI
118+
119+
- A popular React UI framework that follows Google's Material Design.
120+
- Code example:
121+
122+
```jsx []
123+
import Button from '@mui/material/Button';
124+
125+
const App = () => {
126+
return <Button variant="contained" color="primary">Hello World</Button>;
127+
}
128+
129+
```
130+
131+
--
132+
133+
#### Tailwind CSS
134+
135+
- One of my favorite libaries. A utility-first CSS framework packed with classes that can be composed to build any design, directly in your markup.
136+
- Code example:
137+
138+
```jsx []
139+
import { FC } from 'react';
140+
141+
const ButtonProps = {
142+
text: string;
143+
}
144+
export const Button: FC<ButtonProps> = ({text}) => {
145+
return <button class="h-10 px-6 font-semibold rounded-md bg-black text-white" type="submit">
146+
{text}
147+
</button>
148+
}
149+
```

content/use-state.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## State management with `useState` hook
2+
3+
--
4+
5+
#### What does the `useState` hook help with?
6+
7+
- Allows functional components to hold state <!-- .element class="fragment" -->
8+
- Returns a state variable and a function to update it <!-- .element class="fragment" -->
9+
10+
--
11+
12+
### Syntax
13+
14+
```jsx []
15+
const [stateValue, setStateValue] = useState(initialStateValue);
16+
```
17+
18+
--
19+
20+
#### Detailed Example:
21+
22+
```jsx []
23+
import { useState } from 'react';
24+
25+
const Counter = () => {
26+
const [count, setCount] = useState(0);
27+
28+
return (
29+
<div className="flex flex-col gap-4">
30+
<p className="text-xl">You clicked {count} times</p>
31+
<button onClick={() => setCount(count + 1)}>
32+
Click me
33+
</button>
34+
</div>
35+
);
36+
}
37+
38+
```

content/virtual-dom.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Virtual DOM in React
2+
3+
---
4+
5+
## What is DOM?
6+
7+
--
8+
9+
` DOM` stands for "Document Object Model". Which in simple words represents the UI of the application. Whenever the UI changes, the DOM gets updated.
10+
11+
--
12+
13+
As web developers, we usually end up using JavaScript to update/_manipulate_ <!-- .element: class="fragment" --> the DOM.
14+
15+
---
16+
17+
## What is Virtual DOM?
18+
19+
The Virtual DOM is an in-memory representation of the real DOM elements. It's like a lightweight copy of the actual DOM, and it allows React to do its magic behind the scenes, optimizing updates and rendering speed.
20+
21+
--
22+
<!-- .slide: data-auto-animate -->
23+
24+
![Virtual Dom1](assets/images/virtual-dom/virtual-dom-1.png)
25+
<!-- .element data-id="vdom-img" -->
26+
27+
--
28+
<!-- .slide: data-auto-animate -->
29+
30+
![Virtual Dom2](assets/images/virtual-dom/virtual-dom-2.png)
31+
<!-- .element data-id="vdom-img" -->
32+
33+
34+
--
35+
<!-- .slide: data-auto-animate -->
36+
37+
![Virtual Dom3](assets/images/virtual-dom/virtual-dom-3.png)
38+
<!-- .element data-id="vdom-img" -->
39+
40+
41+
--
42+
<!-- .slide: data-auto-animate -->
43+
44+
![Virtual Dom4](assets/images/virtual-dom/virtual-dom-4.png)
45+
<!-- .element data-id="vdom-img" -->
46+
47+
48+
--
49+
<!-- .slide: data-auto-animate -->
50+
51+
![Virtual Dom5](assets/images/virtual-dom/virtual-dom-5.png)
52+
<!-- .element data-id="vdom-img" -->
53+
54+
---
55+
56+
To recap, the Virtual DOM allows React to perform efficient updates by only redrawing nodes that have changed. This results in a significant performance gain, especially in complex applications.
57+
58+
---
59+
60+
## Recap and best practices
61+
62+
- Recap: Virtual DOM updates only what is necessary
63+
- Best Practice: Minimize state updates to optimize React's performance better
64+
- Remember: Virtual DOM is not just a performance feature, it is a programming model that simplifies UI logic for React

data/slides.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"link":"component-lifecycle-react.md","title":"Component Life-cycle in React"},{"link":"conditional-rendering.md","title":"Dynamic & Conditional Rendering in React"},{"link":"event-handlers-in-react.md","title":"Handling events in React"},{"link":"react-fundamentals.md","title":"React Fundamentals"}]
1+
[{"link":"component-lifecycle-react.md","title":"Component Life-cycle in React"},{"link":"conditional-rendering.md","title":"Dynamic & Conditional Rendering in React"},{"link":"event-handlers-in-react.md","title":"Handling events in React"},{"link":"react-fundamentals.md","title":"React Fundamentals"},{"link":"styling-options.md","title":"Styling options in React"},{"link":"use-state.md","title":"State management with `useState` hook"},{"link":"virtual-dom.md","title":"Virtual DOM in React"}]

nodemon.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"watch": ["scripts/extractSlideData.js", "content/**"],
3+
"ext": "md"
4+
}

0 commit comments

Comments
 (0)