-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
dispatch.jsx
60 lines (53 loc) · 1.21 KB
/
dispatch.jsx
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
import React, {useReducer} from 'react';
import blessed from 'blessed';
import {render} from '../src';
const initialState = {count: 0};
function reducer(state, action) {
switch (action.type) {
case 'increment':
return {count: state.count + 1};
case 'decrement':
return {count: state.count - 1};
default:
throw new Error();
}
}
const App = () => {
const [demo, dispatch] = useReducer(reducer, initialState);
return (
<box
label="react-blessed hooks demo"
border={{type: 'line'}}
style={{border: {fg: 'cyan'}}}>
{demo.count}
<button
mouse
border={{type: 'line'}}
height={3}
width={3}
top={2}
left={4}
onPress={a => dispatch({type: 'increment'})}>
+
</button>
<button
mouse
border={{type: 'line'}}
height={3}
width={3}
top={2}
onPress={a => dispatch({type: 'decrement'})}>
-
</button>
</box>
);
};
const screen = blessed.screen({
autoPadding: true,
smartCSR: true,
title: 'react-blessed hooks demo'
});
screen.key(['escape', 'q', 'C-c'], function (ch, key) {
return process.exit(0);
});
render(<App />, screen);