@@ -17,13 +17,13 @@ fn App(cx: Scope) -> Element {
1717 // But `if` statements only run if the conditional is true!
1818 // So we might violate rule 2.
1919 if you_are_happy && you_know_it {
20- let something = use_state ( & cx, || "hands" ) ;
20+ let something = use_state ( cx, || "hands" ) ;
2121 println ! ( "clap your {something}" )
2222 }
2323
2424 // ✅ instead, *always* call use_state
2525 // You can put other stuff in the conditional though
26- let something = use_state ( & cx, || "hands" ) ;
26+ let something = use_state ( cx, || "hands" ) ;
2727 if you_are_happy && you_know_it {
2828 println ! ( "clap your {something}" )
2929 }
@@ -33,12 +33,12 @@ fn App(cx: Scope) -> Element {
3333 // ❌ don't call hooks inside closures!
3434 // We can't guarantee that the closure, if used, will be called at the same time every time
3535 let _a = || {
36- let b = use_state ( & cx, || 0 ) ;
36+ let b = use_state ( cx, || 0 ) ;
3737 b. get ( )
3838 } ;
3939
4040 // ✅ instead, move hook `b` outside
41- let b = use_state ( & cx, || 0 ) ;
41+ let b = use_state ( cx, || 0 ) ;
4242 let _a = || b. get ( ) ;
4343 // ANCHOR_END: closure
4444
@@ -50,12 +50,12 @@ fn App(cx: Scope) -> Element {
5050 // ❌ Do not use hooks in loops!
5151 // In this case, if the length of the Vec changes, we break rule 2
5252 for _name in & names {
53- let is_selected = use_state ( & cx, || false ) ;
53+ let is_selected = use_state ( cx, || false ) ;
5454 println ! ( "selected: {is_selected}" ) ;
5555 }
5656
5757 // ✅ Instead, use a hashmap with use_ref
58- let selection_map = use_ref ( & cx, HashMap :: < & str , bool > :: new) ;
58+ let selection_map = use_ref ( cx, HashMap :: < & str , bool > :: new) ;
5959
6060 for name in & names {
6161 let is_selected = selection_map. read ( ) [ name] ;
0 commit comments