@@ -158,8 +158,28 @@ export const TimeSyncProvider: FC<TimeSyncProviderProps> = ({
158
158
} ;
159
159
160
160
type UseTimeSyncOptions < T = Date > = Readonly < {
161
- idealRefreshIntervalMs : number ;
162
- selectDeps ?: readonly unknown [ ] ;
161
+ /**
162
+ * targetRefreshInterval is the ideal interval of time, in milliseconds,
163
+ * that defines how often the hook should refresh with the newest Date
164
+ * value from TimeSync.
165
+ *
166
+ * Note that a refresh is not the same as a re-render. If the hook is
167
+ * refreshed with a new datetime, but its select callback produces the same
168
+ * value as before, the hook will skip re-rendering.
169
+ *
170
+ * The hook reserves the right to refresh MORE frequently than the
171
+ * specified value if it would guarantee that the hook does not get out of
172
+ * sync with other useTimeSync users that are currently mounted on screen.
173
+ */
174
+ targetRefreshInterval : number ;
175
+
176
+ /**
177
+ * selectDependencies acts like the dependency array for a useMemo callback.
178
+ * Whenever any of the elements in the array change by value, that will
179
+ * cause the select callback to re-run synchronously and produce a new,
180
+ * up-to-date value for the current render.
181
+ */
182
+ selectDependencies ?: readonly unknown [ ] ;
163
183
164
184
/**
165
185
* Allows you to transform any date values received from the TimeSync class.
@@ -189,7 +209,11 @@ type UseTimeSyncOptions<T = Date> = Readonly<{
189
209
* interval.
190
210
*/
191
211
export function useTimeSync < T = Date > ( options : UseTimeSyncOptions < T > ) : T {
192
- const { select, selectDeps, idealRefreshIntervalMs } = options ;
212
+ const {
213
+ select,
214
+ selectDependencies : selectDeps ,
215
+ targetRefreshInterval : idealRefreshIntervalMs ,
216
+ } = options ;
193
217
const timeSync = useContext ( timeSyncContext ) ;
194
218
if ( timeSync === null ) {
195
219
throw new Error ( "Cannot call useTimeSync outside of a TimeSyncProvider" ) ;
0 commit comments