/
index.tsx
36 lines (29 loc) · 727 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
import * as React from 'react'
import { Atom, F } from '@grammarly/focal'
interface CounterState {
readonly count: number
}
interface AppState {
readonly counter: CounterState
}
namespace AppState {
export const defaultState: AppState = {
counter: { count: 0 }
}
}
const Counter = (props: { count: Atom<number> }) =>
<F.div>
You have clicked this button {props.count} time(s).
<button onClick={() => props.count.modify(x => x + 1)}>
Click again?
</button>
</F.div>
const App = (props: { state: Atom<AppState> }) =>
<div>
Hello, world!
<Counter count={props.state.lens('counter', 'count')} />
</div>
export default {
Component: App,
defaultState: AppState.defaultState
}