-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor DateTimeRangePicker again
#1247
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
3e55163 to
09681e6
Compare
3679f13 to
acb6951
Compare
|
|
||
| return () => vi.useRealTimers() | ||
| }) | ||
|
|
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.
this wasn't working before, now it is? ok
| setStartTime(newStart) | ||
| setEndTime(newEnd) | ||
| } | ||
| }, []) |
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.
Certainly no reason not to memoize here. And I need it in the picker because a useCallback depends on this.
DateTimeRangePicker
DateTimeRangePickerDateTimeRangePicker again
| const intervalId = setInterval(() => callbackRef.current?.(), delay) | ||
| return () => clearInterval(intervalId) | ||
| }, [delay]) | ||
| }, [delay, key]) |
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.
Without key, this will only clear (and possibly remake) the interval if the delay changes. But if you want to delete and remake the interval while keeping the delay the same, you change key.
In #1225 I split the picker into a component and a hook, and callers have to use both. As I tried to work on the refetch interval picker, I got madder and madder about that setup, so this is me cleaning that up. The real problem I had that caused the original refactor was that the tests weren't working as I expected. Because the component is split out nicely, the tests can exercise the component but I can still use the hook that wraps the component for the actual code.
Despite the branch name, this does not add any refetch controls. One real change that's made here is the behavior is more correct when switching range presets. As you would expect, the old refetch interval is cleared when the new one is created.