1
1
# use-disposable-list
2
2
3
- A React hook for a disposable list.
3
+ A react hook to create a list of disposable items,
4
4
5
- ``` js
6
- const [notifs , addNotif , removeNotif ] = useDisposableList ({
7
- hideDuration: 300 ,
8
- timeout: 2000 ,
9
- });
5
+ It can be used as a core infra to display a growl notification for ** any** css framework.
6
+
7
+ ### Basic Sample
8
+
9
+ See live in [ Codesandbox] ( https://codesandbox.io/s/clever-cache-y7xw1 )
10
+
11
+ ``` jsx
12
+ import " ./styles.css" ;
13
+ import useDisposableList from " use-disposable-list" ;
14
+
15
+ export default function App () {
16
+ const [notifs , addNotif , removeNotif ] = useDisposableList ({
17
+ hideDuration: 0 ,
18
+ timeout: 2000 ,
19
+ });
20
+
21
+ return (
22
+ < div className= " App" >
23
+ < h1> use- disposable- list< / h1>
24
+ < div>
25
+ < div style= {{ paddingBottom: " 20px" }}>
26
+ < button
27
+ onClick= {() =>
28
+ addNotif ({
29
+ message: " Hello" ,
30
+ level: " info" ,
31
+ description: " World" ,
32
+ })
33
+ }
34
+ >
35
+ info
36
+ < / button>
37
+ < button
38
+ onClick= {() =>
39
+ addNotif ({
40
+ message: " Oh no" ,
41
+ level: " error" ,
42
+ description: " Something bad happened" ,
43
+ })
44
+ }
45
+ >
46
+ error
47
+ < / button>
48
+ < / div>
49
+ {notifs .map (({ id, show, details = { level: " info" } }) => (
50
+ < div>
51
+ < span> {details .message }< / span>
52
+ < button
53
+ onClick= {() => removeNotif (id)}
54
+ style= {{ marginLeft: " 3px" }}
55
+ >
56
+ X
57
+ < / button>
58
+ < / div>
59
+ ))}
60
+ < / div>
61
+ < / div>
62
+ );
63
+ }
10
64
```
11
65
12
- ``` ts
66
+ ### Typescript
67
+
68
+ ``` tsx
69
+ export interface NotificationDef {
70
+ message: string ;
71
+ description? : string ;
72
+ level: " info" | " error" ;
73
+ }
74
+
13
75
interface NotificationsDef {
14
76
id: string ;
15
77
show: boolean ;
@@ -20,6 +82,11 @@ const [notifs, addNotif, removeNotif] = useDisposableList<NotificationDef>({
20
82
hideDuration: 300 ,
21
83
timeout: 2000 ,
22
84
});
85
+
86
+ // ...
23
87
```
24
88
25
- - ` notifs ` is a list of disposable notifications to display
89
+ ### Demos
90
+
91
+ - [ story book] ( https://60afd8ceda1d8b003977ba04-bwpixgfhhi.chromatic.com/ )
92
+ - [ Codesandbox with Bootstrap] ( https://codesandbox.io/s/holy-tdd-t8gr8 )
0 commit comments