clear timeout on unmount
This commit is contained in:
parent
5917e62286
commit
de64694002
@ -20,9 +20,15 @@ const Toast: React.FC<Props> = props => {
|
||||
const [show, setShow] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => setShow(true), 100)
|
||||
setTimeout(() => setShow(false), 3000)
|
||||
setTimeout(props.onClose, 3100)
|
||||
const id1 = setTimeout(() => setShow(true), 100)
|
||||
const id2 = setTimeout(() => setShow(false), 3000)
|
||||
const id3 = setTimeout(props.onClose, 3100)
|
||||
|
||||
return () => {
|
||||
clearTimeout(id1)
|
||||
clearTimeout(id2)
|
||||
clearTimeout(id3)
|
||||
}
|
||||
}, [props.onClose])
|
||||
|
||||
const type = props.type === 'error' ? 'danger' : props.type
|
||||
|
Loading…
Reference in New Issue
Block a user