-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter.coffee
More file actions
27 lines (22 loc) · 876 Bytes
/
counter.coffee
File metadata and controls
27 lines (22 loc) · 876 Bytes
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
import React, { useState,useCallback } from 'react';
import {useWindowWidth} from './myhooks'
export default =>
[value, setValue] = useState(0)
[alert, setAlert] = useState("")
width = useWindowWidth()
add = useCallback => setValue((value + 1),[value])
remove = useCallback =>
if value > 0
setAlert("")
setValue((value - 1),[value])
else
setAlert("That's too low!")
<div style={{margin:10,padding:"10px 15px",background:"#eee",boder:"1px solid #ddd",display:"inline-block",borderRadius:4}} >
<button style={{padding:"5px 8px",fontSize:14,borderRadius:4,margin:10}} onClick={remove}>Remove</button>
Counter: {value}
<button style={{padding:"5px 8px",fontSize:14,borderRadius:4,margin:10}} onClick={add}>Add</button>
{if alert && value == 0
<p>{alert}</p>
}
<p>Window width is {width}px</p>
</div>