/
githubmirror
/
ionic
Обзор
Документация
Войти
/
githubmirror
/
ionic
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/react/src/lifecycle/IonLifeCycleHOC.tsx
54 строки
1 KB
Amanda Johnston
chore(many): replace `any` types and add tech debt tickets (#26293)
06 янв 2023, 18:34
Не верифицирован
06 янв 2023, 18:34
c2e1ad3
Код
Авторство
О чём код?
import React from 'react'; import { IonLifeCycleContext } from '../contexts/IonLifeCycleContext'; // TODO(FW-2959): types export const withIonLifeCycle = (WrappedComponent: React.ComponentType<any>) => { return class IonLifeCycle extends React.Component<any, any> { context!: React.ContextType<typeof IonLifeCycleContext>; componentRef = React.createRef<any>(); constructor(props: any) { super(props); } componentDidMount() { const element = this.componentRef.current; this.context.onIonViewWillEnter(() => { if (element && element.ionViewWillEnter) { element.ionViewWillEnter(); } }); this.context.onIonViewDidEnter(() => { if (element && element.ionViewDidEnter) { element.ionViewDidEnter(); } }); this.context.onIonViewWillLeave(() => { if (element && element.ionViewWillLeave) { element.ionViewWillLeave(); } }); this.context.onIonViewDidLeave(() => { if (element && element.ionViewDidLeave) { element.ionViewDidLeave(); } }); } render() { return ( <IonLifeCycleContext.Consumer> {(context) => { this.context = context; return <WrappedComponent ref={this.componentRef} {...this.props} />; }} </IonLifeCycleContext.Consumer> ); } }; };