-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: refresh plugins interval #3663
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {useEffect, useRef} from 'react' | ||
|
||
export const useInterval = (callback: () => void, delay: number | null) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should or need to override this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why we need to wrap the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a general hook to use interval with self-cleaning. |
||
const savedCallback = useRef(callback); | ||
|
||
// Remember the latest callback if it changes | ||
useEffect(() => { | ||
savedCallback.current = callback; | ||
}, [callback]) | ||
Comment on lines
+6
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the practice |
||
|
||
// Set up the interval | ||
useEffect(() => { | ||
// Don't schedule if no delay is specified | ||
// Note: 0 is a valid value for delay | ||
if (!delay && delay !== 0) { | ||
return; | ||
} | ||
|
||
const id = setInterval(() => savedCallback.current(), delay); | ||
|
||
return () => clearInterval(id); | ||
}, [delay]) | ||
} |
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.
In general this is not a good name. If a name is "DoSomething1andDoSomething2" it means that there are 2 functions: "DoSomething1" and "DoSomething2". So we should just call "DoSomething1" and "DoSomething2" in a row instead of creating another function. But since there's a temporal coupling, I don't feel strongly about this
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 can change it if you have a better one