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:
Ely Lucas
2021-10-05 06:44:40 -06:00
committed by GitHub
parent f112ad4490
commit 2c97712601
11 changed files with 276 additions and 146 deletions

View File

@ -1,9 +1,5 @@
import {
PickerButton,
PickerColumn,
PickerOptions,
pickerController,
} from '@ionic/core';
import { PickerButton, PickerColumn, PickerOptions, pickerController } from '@ionic/core';
import { useCallback } from 'react';
import { HookOverlayOptions } from './HookOverlayOptions';
import { useController } from './useController';
@ -18,12 +14,10 @@ export function useIonPicker(): UseIonPickerResult {
pickerController
);
function present(columns: PickerColumn[], buttons?: PickerButton[]): void;
function present(options: PickerOptions & HookOverlayOptions): void;
function present(
const present = useCallback((
columnsOrOptions: PickerColumn[] | (PickerOptions & HookOverlayOptions),
buttons?: PickerButton[]
) {
) => {
if (Array.isArray(columnsOrOptions)) {
controller.present({
columns: columnsOrOptions,
@ -32,7 +26,7 @@ export function useIonPicker(): UseIonPickerResult {
} else {
controller.present(columnsOrOptions);
}
}
}, [controller.present]);
return [present, controller.dismiss];
}