You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- While the caveats exist due to the extensive types of expressions that javascript has, it's recommended that you use a cloned variable and then just assigned the modification to the reactive variable if you plan to use it right now.
15
+
16
+
- While the caveats exist due to the extensive types of expressions that javascript has, it's recommended that you use a cloned variable and then just assigned the modification to the reactive variable if you plan to use it right now.
17
+
17
18
```jsx
19
+
functionComponent() {
20
+
let $text =''
18
21
19
-
functionComponent(){
20
-
let $text ="";
21
-
22
-
return<>
23
-
<input value={$text} onChange={e=> {
24
-
$text =e.target.value;
25
-
// some code
26
-
27
-
// won't work...
28
-
$text =$text.toUpperCase()
29
-
}}/>
30
-
</>
22
+
return (
23
+
<>
24
+
<input
25
+
value={$text}
26
+
onChange={(e) => {
27
+
$text =e.target.value
28
+
// some code
29
+
30
+
// won't work...
31
+
$text =$text.toUpperCase()
32
+
}}
33
+
/>
34
+
</>
35
+
)
31
36
}
32
37
33
-
// CAN be written as
34
-
35
-
functionComponent(){
36
-
let $text ="";
37
-
38
-
return<>
39
-
<input value={$text} onChange={e=> {
40
-
constval=e.target.value;
41
-
// some code
42
-
43
-
// will work...
44
-
$text =val.toUpperCase()
45
-
}}/>
46
-
</>
47
-
}
38
+
// CAN be written as
48
39
40
+
functionComponent() {
41
+
let $text =''
42
+
43
+
return (
44
+
<>
45
+
<input
46
+
value={$text}
47
+
onChange={(e) => {
48
+
constval=e.target.value
49
+
// some code
50
+
51
+
// will work...
52
+
$text =val.toUpperCase()
53
+
}}
54
+
/>
55
+
</>
56
+
)
57
+
}
49
58
```
50
59
60
+
- This is still react state so you cannot do dependent state updates at once,
61
+
62
+
```jsx
63
+
// the value of `length` will still be the older value of $text and not the latest one
64
+
changeHandler(){
65
+
$text = value
66
+
$length =$text.length
67
+
}
51
68
69
+
// you'll still have to consider that dependent values need to be handled with useEffect
0 commit comments