mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 18:54:11 +08:00
fix(react): overlay hooks memorised properly to prevent re-renders (#24010)
resolves #23741 Co-authored-by: Fabrice <fabrice@weinberg.me>
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { OverlayEventDetail } from '@ionic/core';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { attachProps } from '../components/utils';
|
||||
@ -52,7 +52,7 @@ export function useOverlay<
|
||||
}
|
||||
}, [component, containerElRef.current, isOpen, componentProps]);
|
||||
|
||||
const present = async (options: OptionsType & HookOverlayOptions) => {
|
||||
const present = useCallback(async (options: OptionsType & HookOverlayOptions) => {
|
||||
if (overlayRef.current) {
|
||||
return;
|
||||
}
|
||||
@ -96,13 +96,13 @@ export function useOverlay<
|
||||
containerElRef.current = undefined;
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const dismiss = async () => {
|
||||
const dismiss = useCallback(async () => {
|
||||
overlayRef.current && await overlayRef.current.dismiss();
|
||||
overlayRef.current = undefined;
|
||||
containerElRef.current = undefined;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return {
|
||||
present,
|
||||
|
Reference in New Issue
Block a user