mirror of
https://github.com/zadam/trilium.git
synced 2025-10-31 18:36:30 +01:00
refactor(react): fix a few more rules of hooks violations
This commit is contained in:
@@ -509,4 +509,16 @@ export function useLegacyImperativeHandlers(handlers: Record<string, Function>)
|
||||
useEffect(() => {
|
||||
Object.assign(parentComponent as never, handlers);
|
||||
}, [ handlers ]);
|
||||
}
|
||||
|
||||
export function useSyncedRef<T>(externalRef?: RefObject<T>, initialValue: T | null = null): RefObject<T> {
|
||||
const ref = useRef<T>(initialValue);
|
||||
|
||||
useEffect(() => {
|
||||
if (externalRef) {
|
||||
externalRef.current = ref.current;
|
||||
}
|
||||
}, [ ref, externalRef ]);
|
||||
|
||||
return ref;
|
||||
}
|
||||
Reference in New Issue
Block a user