-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.txt
More file actions
117 lines (94 loc) · 2.9 KB
/
notes.txt
File metadata and controls
117 lines (94 loc) · 2.9 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
npm -v
npx -v
node -v
node modules will be adede to the path after npm install <package>
npm - node package manager, used to manage all dependencies
npx - node package executor
npm - node package manager, used to manage all dependencies
npx - node package executor
npm init - initialization of npm, it will create package.json
To create React app:
npx create-react-app todo-app
cd todo-app
npm start
JSX- javascript executor
Stricter than HTML
start and ending tag should be proper
multiple tagss should be wrapped with <> </>
JSX - In older browser, babel enables to convert to modern javascript
ES - Ecmascript
import './App.css';
import {LearningComponent} from './components/learning-examples/LearningComponent'
function App() {
return (
<div className="App">
<b>The praveen's Application</b>
<LearningComponent/>
</div>
);
}
export default App; --> no need to mention near import {}
export function App() {
return (
<div className="App">
<b>The praveen's Application</b>
<LearningComponent/>
</div>
);
}
Best practices:
Move each component to separate folder
part of Component:
1. View - JSX
2. Logic - JS
3. Styling - CSS
4. State - Internal data store
5. Props - Pass Data
Hooks:
const [count,setCount]=useState(0);
setCount(count+1);
useState(0) will be having array of 2 elements.
first one initial value and second one is function
Props:
In return - we can add properties to function
<Counter proeprty1="1" property2="2"/>
#old
function Counter(proeprties){
console.log(properties.property1);
}
#new - modern
function Counter({proeprty1,proeprty2}){
console.log(property1);
}
export default function CounterButton({by,incrementMethod,decrementMethod}) {
return (
<div className="Counter">
<div>
<button className="counterButton" onClick={()=>incrementMethod(by)}>+{by}</button>
<button className="counterButton" onClick={()=>decrementMethod(by)}>-{by}</button>
</div>
</div>
);
}
----------------------------------------------------
export default function Counter() {
const [count,setCount]=useState(0);
function counterButtonIncrement(by){
setCount(count+by);
}
function counterButtonDecrement(by){
setCount(count-by);
}
function counterButtonClear(){
setCount(0);
}
return (
<div className="Counter">
<span className="count">{count}</span>
<CounterButton by={1} incrementMethod={counterButtonIncrement} decrementMethod={counterButtonDecrement}/>
<CounterButton by={2} incrementMethod={counterButtonIncrement} decrementMethod={counterButtonDecrement}/>
<CounterButton by={5} incrementMethod={counterButtonIncrement} decrementMethod={counterButtonDecrement}/>
<button className="counterButtonClear" onClick={counterButtonClear}>Reset</button>
</div>
);
}