1
- import React , { useState } from 'react' ;
1
+ import React , { useCallback , useMemo , useState } from 'react' ;
2
2
import PageContainer from '../../layouts/pages/pageContainer/PageContainer' ;
3
3
import { Button , Col , Row , Space } from 'antd' ;
4
4
import { v4 } from 'uuid' ;
5
5
import Text from 'antd/lib/typography/Text' ;
6
6
import ExternalLink from '../../components/ExternalLink' ;
7
7
import CopyButton from '../../components/copyButton/CopyButton' ;
8
8
import getNpmPackageLink from '../../utils/getNpmPackageLink' ;
9
+ import useStateProducer from '../../hooks/useStateProducer' ;
10
+ import TextArea from 'antd/lib/input/TextArea' ;
11
+ import { useDidMount } from 'rooks' ;
9
12
10
13
const titleExtra = (
11
14
< Text type = "secondary" >
@@ -14,13 +17,26 @@ const titleExtra = (
14
17
) ;
15
18
16
19
const UuidGeneratorPage = ( ) => {
17
- const [ uuid , setUuid ] = useState < string > ( v4 ( ) ) ;
20
+ const [ uuid , setUuid ] = useState < string > ( ) ;
21
+ const [ history , setHistory ] = useState < string [ ] > ( [ ] ) ;
22
+ const produceHistory = useStateProducer ( setHistory ) ;
18
23
19
- const generate = ( ) => {
24
+ const historyString = useMemo < string > ( ( ) => {
25
+ return history . join ( '\n' ) ;
26
+ } , [ history ] ) ;
27
+
28
+ const generate = useCallback ( ( ) => {
20
29
const newUuid = v4 ( ) ;
21
30
setUuid ( newUuid ) ;
31
+ produceHistory ( ( history ) => {
32
+ history . unshift ( newUuid ) ;
33
+ } ) ;
22
34
return newUuid ;
23
- } ;
35
+ } , [ ] ) ;
36
+
37
+ useDidMount ( ( ) => {
38
+ generate ( ) ;
39
+ } ) ;
24
40
25
41
return (
26
42
< PageContainer title = "UUID Generator" titleExtra = { titleExtra } >
@@ -32,12 +48,13 @@ const UuidGeneratorPage = () => {
32
48
</ Text >
33
49
</ Space >
34
50
</ Row >
35
- < Space >
51
+ < Space className = "mb-2" >
36
52
< Button onClick = { generate } > Generate</ Button >
37
53
< CopyButton value = { uuid } onClick = { generate } >
38
54
Generate and copy
39
55
</ CopyButton >
40
56
</ Space >
57
+ < TextArea value = { historyString } rows = { 6 } />
41
58
</ Col >
42
59
</ PageContainer >
43
60
) ;
0 commit comments