-
-
Notifications
You must be signed in to change notification settings - Fork 609
/
static.tsx
54 lines (45 loc) · 919 Bytes
/
static.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
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import {Box, Text, render, Static} from '../../src/index.js';
function Example() {
const [tests, setTests] = React.useState<
Array<{
id: number;
title: string;
}>
>([]);
React.useEffect(() => {
let completedTests = 0;
let timer: NodeJS.Timeout | undefined;
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 />);