Skip to content

Commit

Permalink
fix: Should cancel timeout if not reach align condition
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Oct 11, 2019
1 parent 4e9f33e commit 395022b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Align.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const Align: React.RefForwardingComponent<RefAlign, AlignProps> = (
// ===================== Align ======================
const forceAlignRef = React.useRef<Function>();

const [forceAlign, cancelForceAlign] = useBuffer(() => {
forceAlignRef.current();
}, monitorBufferTime);

forceAlignRef.current = () => {
if (!disabled && target) {
const source = findDOMNode<HTMLElement>(nodeRef.current);
Expand All @@ -79,13 +83,11 @@ const Align: React.RefForwardingComponent<RefAlign, AlignProps> = (
if (onAlign) {
onAlign(source, result);
}
} else {
cancelForceAlign();
}
};

const [forceAlign, cancelForceAlign] = useBuffer(() => {
forceAlignRef.current();
}, monitorBufferTime);

// ===================== Effect =====================
// Listen for target updated
const resizeMonitor = React.useRef<MonitorRef>({
Expand Down

0 comments on commit 395022b

Please sign in to comment.