mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
fix: quick search tips follow when resize (#1580)
Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
import { jotaiWorkspacesAtom, workspacesAtom } from '../atoms';
|
||||
import { WorkspacePlugins } from '../plugins';
|
||||
@@ -71,3 +71,25 @@ export function useWorkspacesHelper() {
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export const useElementResizeEffect = (
|
||||
element: Element | null,
|
||||
fn: () => void | (() => () => void),
|
||||
// TODO: add throttle
|
||||
throttle = 0
|
||||
) => {
|
||||
useEffect(() => {
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
let dispose: void | (() => void);
|
||||
const resizeObserver = new ResizeObserver(entries => {
|
||||
dispose = fn();
|
||||
});
|
||||
resizeObserver.observe(element);
|
||||
return () => {
|
||||
dispose?.();
|
||||
resizeObserver.disconnect();
|
||||
};
|
||||
}, [element, fn]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user