File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed
examples/basic/src/components Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,10 @@ interface CountStore {
6
6
increment : ( ) => void
7
7
decrement : ( ) => void
8
8
}
9
+
9
10
const useCount = quark < CountStore > ( set => ( {
10
11
count : 0 ,
12
+
11
13
increment : ( ) => {
12
14
set ( prev => ( { count : prev . count + 1 } ) )
13
15
} ,
@@ -18,6 +20,7 @@ const useCount = quark<CountStore>(set => ({
18
20
19
21
export function Counter ( ) {
20
22
const { count, increment, decrement } = useCount ( )
23
+
21
24
return (
22
25
< div >
23
26
< p > Count: { count } </ p >
Original file line number Diff line number Diff line change @@ -13,39 +13,40 @@ const useStore = quark<State>(set => ({
13
13
setText : text => set ( { text } ) ,
14
14
} ) )
15
15
16
- // 자식 컴포넌트
16
+ let parentRenderCount = 0
17
+ let childRenderCount = 0
18
+
17
19
export function ChildComponent ( ) {
18
20
const count = useStore ( state => state . count )
19
21
20
- console . log ( 'ChildComponent 렌더링' )
22
+ console . log ( 'ChildComponent render count' , ++ childRenderCount )
21
23
22
24
return (
23
25
< div >
24
- < h2 > 자식 컴포넌트 </ h2 >
25
- < p > 카운트 값 : { count } </ p >
26
+ < h2 > ChildComponent </ h2 >
27
+ < p > count : { count } </ p >
26
28
</ div >
27
29
)
28
30
}
29
31
30
- // 부모 컴포넌트
31
32
export function ParentComponent ( ) {
32
33
const { text, incrementCount, setText } = useStore ( state => ( {
33
34
text : state . text ,
34
35
incrementCount : state . incrementCount ,
35
36
setText : state . setText ,
36
37
} ) )
37
38
38
- console . log ( 'ParentComponent 렌더링' )
39
+ console . log ( 'ParentComponent render count' , ++ parentRenderCount )
39
40
40
41
return (
41
42
< div >
42
- < h1 > 부모 컴포넌트 </ h1 >
43
- < button onClick = { incrementCount } > 카운트 증가 </ button >
43
+ < h1 > ParentComponent </ h1 >
44
+ < button onClick = { incrementCount } > increment count </ button >
44
45
< input
45
46
type = 'text'
46
47
value = { text }
47
48
onChange = { e => setText ( e . target . value ) }
48
- placeholder = '텍스트 입력 '
49
+ placeholder = 'input text '
49
50
/>
50
51
< ChildComponent />
51
52
</ div >
You can’t perform that action at this time.
0 commit comments