-
Notifications
You must be signed in to change notification settings - Fork 0
/
counterNested.js
62 lines (57 loc) · 1.46 KB
/
counterNested.js
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
import { useState } from 'react';
import { createHook } from 'garfio/container';
function counter(initial = 0) {
const [count, setCount] = useState(initial);
const increment = () => setCount(count + 1);
return [count, increment];
}
const useCounter = createHook(counter);
const CounterContainer = useCounter.Container;
function Button() {
const [, increment] = useCounter();
return <button onClick={increment}>+</button>;
}
function Count() {
const [count] = useCounter();
return <p>{count}</p>;
}
export default () => (
<>
<CounterContainer initialArg={3}>
<Count />
<Button />
</CounterContainer>
<CounterContainer>
<Count />
<Button />
<CounterContainer>
<Count />
<Button />
<CounterContainer initialArg={4}>
<Count />
<Button />
<CounterContainer initialArg={4}>
<Count />
<Button />
<CounterContainer initialArg={4}>
<Count />
<Button />
<CounterContainer initialArg={4}>
<Count />
<Button />
</CounterContainer>
</CounterContainer>
</CounterContainer>
</CounterContainer>
</CounterContainer>
</CounterContainer>
<CounterContainer>
<Count />
<Button />
<CounterContainer initialArg={3}>
<Count />
<Button />
</CounterContainer>
</CounterContainer>
</>
);