-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.tsx
41 lines (34 loc) · 843 Bytes
/
index.tsx
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
import * as React from 'react';
type CounterState = {
count: number,
};
type ChildProps = CounterState & {
increment(d: number): void,
};
type CounterProps = {
render(state: ChildProps): React.ReactNode,
};
class CounterDataProvider extends React.Component<CounterProps, CounterState> {
readonly state: CounterState = {
count: 44,
};
increment = (delta: number) =>
this.setState({ count: this.state.count + delta })
render() {
return this.props.render({
...this.state,
increment: this.increment,
});
}
}
export default () => (
<CounterDataProvider
render={(props: ChildProps) => (
<div>
<h1>Count: {props.count}</h1>
<button onClick={() => props.increment(1)}>+1</button>
<button onClick={() => props.increment(-1)}>-1</button>
</div>
)}
/>
);