-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial.txt
61 lines (49 loc) · 1.23 KB
/
tutorial.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useEffect, useState } from 'react';
import './App.css';
const Person = (props) => {
return (
<>
Name: {props.name} <br />
Last Name: {props.lname}<br />
Age: 30<br />
<br />
</>
)
}
const Counter = () => {
const [counter, setCounter] = useState(0);
useEffect(() => { //effects when page reloads
// setCounter(100);
alert("Counter Changed"); //will be called whenever counter changes
}, [counter] //dependency array )
return (
<div className='Counter'>
<button onClick={() => setCounter((prevCount) => prevCount - 1)}>-</button>
<h1>{counter}</h1>
<button onClick={() => setCounter((prevCount) => prevCount + 1)}>+</button>
</div>
)
}
const App = () => {
const name = 'Saumya';
const isNameDefined = true;
return (
<div className="App">
<Counter />
<Person name={'Shruti'} lname={'Shahi'} />
<Person />
<h1> Hello, {isNameDefined ? name : 'NameLess'}! </h1>
{name ? (
<>
test {name}
</>
) : (
<>
<h2>test</h2>
<h1>There is no name? </h1>
</>
)}
</div>
);
}
export default App;