mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-06 23:43:32 +00:00
c65d92ee4c
* beginnings of app directory * settings mostly good * colocate way more components * flatten components folder * reexport QueryClientProvider from client * move CodeBlock back to interface * colocate Explorer, KeyManager + more * goddamn captialisation * get toasts out of components * please eslint * no more src directory * $ instead of : * added back RowHeader component * fix settings modal padding * more spacing, less margin * fix sidebar locations button * fix tags sidebar link * clean up back button * added margin to explorer context menu to prevent contact with edge of viewport * don't export QueryClientProvider from @sd/client * basic guidelines * import interface correctly * remove old demo data * fix onboarding layout * fix onboarding navigation * fix key manager settings button --------- Co-authored-by: Jamie Pine <ijamespine@me.com>
20 lines
693 B
TypeScript
20 lines
693 B
TypeScript
import { useEffect } from 'react';
|
|
import { FieldValues, UseFormReturn, WatchObserver } from 'react-hook-form';
|
|
import { useDebouncedCallback } from 'use-debounce';
|
|
|
|
export function useDebouncedFormWatch<
|
|
TFieldValues extends FieldValues = FieldValues,
|
|
TContext = any
|
|
>(form: UseFormReturn<TFieldValues, TContext>, callback: WatchObserver<TFieldValues>) {
|
|
const debounced = useDebouncedCallback(callback, 500);
|
|
|
|
// listen for any form changes
|
|
useEffect(() => {
|
|
const { unsubscribe } = form.watch(debounced);
|
|
return () => unsubscribe();
|
|
}, [form, debounced]);
|
|
|
|
// persist unchanged data when the component is unmounted
|
|
useEffect(() => () => debounced.flush(), [debounced, form]);
|
|
}
|