-
Notifications
You must be signed in to change notification settings - Fork 580
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
Store Rubric in IndexedDB #9840
Changes from 1 commit
6a63633
eb39f55
ac06f95
f07434f
db4440d
3d531a4
5068f1c
1dfc266
8d0e79c
de5d7b5
05267c0
0619155
d3a95cb
8f86a03
cc03024
3f6314c
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,28 @@ | ||
import { useRef } from "react"; | ||
import { Input, InputProps } from "react-common/components/controls/Input"; | ||
|
||
export interface DebouncedInputProps extends InputProps { | ||
intervalMs?: number | undefined; | ||
} | ||
|
||
// This functions like the React Common Input, but debounces onChange calls | ||
// so they only fire once every `interval` milliseconds (defined in props) | ||
export const DebouncedInput: React.FC<DebouncedInputProps> = props => { | ||
const timerId = useRef<NodeJS.Timeout | undefined>(undefined); | ||
|
||
const onChangeDebounce = (newValue: string) => { | ||
if (timerId.current) { | ||
clearTimeout(timerId.current); | ||
} | ||
|
||
timerId.current = setTimeout(() => { | ||
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 is the expected behavior if the component unmounts while a timeout is pending? 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. Hmm good question. I'll add some code to fire the onChange immediately if we're umounting and the timeout is pending. |
||
if (!props.onChange) { | ||
return; | ||
} | ||
|
||
props.onChange(newValue); | ||
}, props.intervalMs ?? 500); | ||
}; | ||
|
||
return <Input {...props} onChange={onChangeDebounce} />; | ||
}; |
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.
Consider assigning the default value here so it's less buried and available to intellisense.
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.
I don't think I can set it here, since this is an interface, but I've moved it up to the DebouncedInput parameter definition and added a comment here instead.