forked from vadimdemedes/ink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic.js
50 lines (41 loc) · 852 Bytes
/
static.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
'use strict';
const React = require('react');
const {render, Static, Box, Text} = require('../..');
const Example = () => {
const [tests, setTests] = React.useState([]);
React.useEffect(() => {
let completedTests = 0;
let timer;
const run = () => {
if (completedTests++ < 10) {
setTests(previousTests => [
...previousTests,
{
id: previousTests.length,
title: `Test #${previousTests.length + 1}`
}
]);
timer = setTimeout(run, 100);
}
};
run();
return () => {
clearTimeout(timer);
};
}, []);
return (
<>
<Static items={tests}>
{test => (
<Box key={test.id}>
<Text color="green">✔ {test.title}</Text>
</Box>
)}
</Static>
<Box marginTop={1}>
<Text dimColor>Completed tests: {tests.length}</Text>
</Box>
</>
);
};
render(<Example />);