0

Implementing an Ionic Modal as a React Component I got this message:

Type '({ onClose, tipo }: PropsWithChildren<{ onClose: any; tipo: number; }>) => Element | undefined' is not assignable to type 'FC<{ onClose: any; tipo: number; }>'. Type 'Element | undefined' is not assignable to type 'ReactElement<any, any> | null'. Type 'undefined' is not assignable to type 'ReactElement<any, any> | null'.ts(2322)

I don't see the problem because the component returns elements. So it is not a function return problem.

This is the code in question.

const MyModal: React.FC<{ onClose: any; tipo: number }> = ({
  onClose,
  tipo
}) => {
  if (tipo === 0) {
    return (
      <>
        <IonHeader>
          <IonToolbar>
            <IonIcon
              icon={arrowBack}
              onClick={() => onClose(null)}
              slot="start"
              id="flecha-volver"
            >
              {" "}
            </IonIcon>
          </IonToolbar>
        </IonHeader>
        <IonContent>
          <div id="contenedor-central">
            <IonGrid>
              <IonRow>
                <strong id="elementos">Usuario no registrado</strong>
              </IonRow>
              <IonRow>
                <IonButton href="/registro" id="elementos">
                  Registrarse
                </IonButton>
              </IonRow>
            </IonGrid>
          </div>
        </IonContent>
      </>
    );
  }
  if (tipo === 1) {
    return (
      <>
        <IonHeader>
          <IonToolbar>
            <IonIcon
              icon={arrowBack}
              onClick={() => onClose(null)}
              slot="start"
              id="flecha-volver"
            ></IonIcon>
          </IonToolbar>
        </IonHeader>
        <IonContent>
          <div id="contenedor-central">
            <strong>Usuario no registrado</strong>
          </div>
          <IonButton href="/registro">Registrarse</IonButton>
          <IonItem>Click List Item To Return Selected Value</IonItem>
        </IonContent>
      </>
    );
  }
  if (tipo === 2) {
    return (
      <>
        <IonHeader>
          <IonToolbar>
            <IonIcon
              icon={arrowBack}
              onClick={() => onClose(null)}
              slot="start"
              id="flecha-volver"
            >
              {" "}
            </IonIcon>
          </IonToolbar>
        </IonHeader>
        <IonContent>
          <div id="contenedor-central">
            <IonGrid>
              <IonRow>
                <strong id="elementos">Categorías</strong>
              </IonRow>
              <IonRow>
                <IonButton href="/registro" id="elementos">
                  Registrarse
                </IonButton>
              </IonRow>
            </IonGrid>
          </div>
        </IonContent>
      </>
    );
  }
};
awran5
  • 4,333
  • 2
  • 15
  • 32
Julián Oviedo
  • 564
  • 5
  • 19

1 Answers1

0

if typo has only three possible values define it like so

type Typo = 1 | 2 | 3;
const MyModal: React.FC<{onClose: any; tipo: Typo;}>

Your error must vanish :)

Wonkledge
  • 1,732
  • 7
  • 16