mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
chore(react): migrate to eslint, add prettier (#26633)
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
import { AnimationBuilder } from '@ionic/core/components';
|
||||
import type { AnimationBuilder } from '@ionic/core/components';
|
||||
import React, { createElement } from 'react';
|
||||
|
||||
import { NavContext } from '../contexts/NavContext';
|
||||
import { RouterOptions } from '../models';
|
||||
import { RouterDirection } from '../models/RouterDirection';
|
||||
import type { RouterOptions } from '../models';
|
||||
import type { RouterDirection } from '../models/RouterDirection';
|
||||
|
||||
import {
|
||||
attachProps,
|
||||
@ -27,24 +27,21 @@ interface IonicReactInternalProps<ElementType> extends React.HTMLAttributes<Elem
|
||||
routerAnimation?: AnimationBuilder;
|
||||
}
|
||||
|
||||
export const createRoutingComponent = <PropType, ElementType>(
|
||||
tagName: string,
|
||||
customElement?: any
|
||||
) => {
|
||||
export const createRoutingComponent = <PropType, ElementType>(tagName: string, customElement?: any) => {
|
||||
defineCustomElement(tagName, customElement);
|
||||
|
||||
const displayName = dashToPascalCase(tagName);
|
||||
const ReactComponent = class extends React.Component<IonicReactInternalProps<PropType>> {
|
||||
context!: React.ContextType<typeof NavContext>;
|
||||
ref: React.RefObject<HTMLElement>;
|
||||
stableMergedRefs: React.RefCallback<HTMLElement>
|
||||
stableMergedRefs: React.RefCallback<HTMLElement>;
|
||||
|
||||
constructor(props: IonicReactInternalProps<PropType>) {
|
||||
super(props);
|
||||
// Create a local ref to to attach props to the wrapped element.
|
||||
this.ref = React.createRef();
|
||||
// React refs must be stable (not created inline).
|
||||
this.stableMergedRefs = mergeRefs(this.ref, this.props.forwardedRef)
|
||||
this.stableMergedRefs = mergeRefs(this.ref, this.props.forwardedRef);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -60,17 +57,12 @@ export const createRoutingComponent = <PropType, ElementType>(
|
||||
const { routerLink, routerDirection, routerOptions, routerAnimation } = this.props;
|
||||
if (routerLink !== undefined) {
|
||||
e.preventDefault();
|
||||
this.context.navigate(
|
||||
routerLink,
|
||||
routerDirection,
|
||||
undefined,
|
||||
routerAnimation,
|
||||
routerOptions
|
||||
);
|
||||
this.context.navigate(routerLink, routerDirection, undefined, routerAnimation, routerOptions);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { children, forwardedRef, style, className, ref, ...cProps } = this.props;
|
||||
|
||||
const propsToPass = Object.keys(cProps).reduce((acc, name) => {
|
||||
|
Reference in New Issue
Block a user