Skip to content

Commit 7230dde

Browse files
committed
exam: improve example code readability and structure
- Add render count display - Convert Korean text to English - Add spacing to separate state and actions in counter store
1 parent 1b0e12b commit 7230dde

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

examples/basic/src/components/counter.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ interface CountStore {
66
increment: () => void
77
decrement: () => void
88
}
9+
910
const useCount = quark<CountStore>(set => ({
1011
count: 0,
12+
1113
increment: () => {
1214
set(prev => ({ count: prev.count + 1 }))
1315
},
@@ -18,6 +20,7 @@ const useCount = quark<CountStore>(set => ({
1820

1921
export function Counter() {
2022
const { count, increment, decrement } = useCount()
23+
2124
return (
2225
<div>
2326
<p>Count: {count}</p>

examples/basic/src/components/render-count.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,40 @@ const useStore = quark<State>(set => ({
1313
setText: text => set({ text }),
1414
}))
1515

16-
// 자식 컴포넌트
16+
let parentRenderCount = 0
17+
let childRenderCount = 0
18+
1719
export function ChildComponent() {
1820
const count = useStore(state => state.count)
1921

20-
console.log('ChildComponent 렌더링')
22+
console.log('ChildComponent render count', ++childRenderCount)
2123

2224
return (
2325
<div>
24-
<h2>자식 컴포넌트</h2>
25-
<p>카운트 값: {count}</p>
26+
<h2>ChildComponent</h2>
27+
<p>count: {count}</p>
2628
</div>
2729
)
2830
}
2931

30-
// 부모 컴포넌트
3132
export function ParentComponent() {
3233
const { text, incrementCount, setText } = useStore(state => ({
3334
text: state.text,
3435
incrementCount: state.incrementCount,
3536
setText: state.setText,
3637
}))
3738

38-
console.log('ParentComponent 렌더링')
39+
console.log('ParentComponent render count', ++parentRenderCount)
3940

4041
return (
4142
<div>
42-
<h1>부모 컴포넌트</h1>
43-
<button onClick={incrementCount}>카운트 증가</button>
43+
<h1>ParentComponent</h1>
44+
<button onClick={incrementCount}>increment count</button>
4445
<input
4546
type='text'
4647
value={text}
4748
onChange={e => setText(e.target.value)}
48-
placeholder='텍스트 입력'
49+
placeholder='input text'
4950
/>
5051
<ChildComponent />
5152
</div>

0 commit comments

Comments
 (0)