-
Notifications
You must be signed in to change notification settings - Fork 225
Conversation
20bae4c
to
420e8d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Good to see this shared within Quilt so we can use it everywhere 💯
Bonus points for the fixed grammar 😂
import {useEffect, useState} from 'react'; | ||
|
||
export function useDelayedCallback(callback: () => void, delay: number) { | ||
const [timeoutId, setTimeoutId] = useState<ReturnType<typeof setTimeout>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReturnType<typeof setTimeout>
🎉
fakeComponent.unmount(); | ||
|
||
fakeComponent.act(() => { | ||
clock.tick(delay - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be delay
instead of delay - 1
?
If you haven't reached the delay the callback shouldn't be called wether the component unmounted or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right. we don't even need the clock tbh. just the unmount!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments, but otherwise it looks good indeed. And thanks for the grammar fixes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great contribution 👍 💯
420e8d0
to
a28c0fa
Compare
Description
Adds a new
useDelayedCallback
hook to thereact-hooks
package.It's useful for when you want to call a function after a given delay. For example, in
web
, we are currently looking to use it to call theonClose()
of aModal
after a slight delay, in order to wait for the progress bar to become 100% filled visually. Without the delay, theModal
closes abruptly before the progress bar reaches 100% visually.This PR also introduces minor corrections in
README.md
to fix grammar errors/typos/inconsistent verb tenses.Type of change
Checklist