Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
How can i pass a boolean state in reactjs with typescript

i have 2 component order.tsx and ModalComponent.tsx..

here my order.tsx code

// state

const [modal, setModal] = useState(false);

// modal component

<Modal item={dataDetail} showModal={false} />

and my ModalComponent.tsx code

    import Link from "next/link";
import Image from "next/image";
import bgImg from "./../../../../public/assets/background_card.png";
import { formatRupiah } from "../../../helpers";
import ProductImage from "../../../../public/assets/product-list.jpg";
import styles from "../../../../styles/pages/Order.module.scss";
import moment from "moment";
import { Col, Row, Modal, Form } from "react-bootstrap";
import { useEffect, useState } from "react";

interface ItemProps {
  created_at: string;
  quantity: number;
  total_price: number;
  buyer_name: string;
  buyer_phone: number;
  buyer_email: string;
  buyer_address: string;
  order_status: string;
}

interface DetailProps {
  item: ItemProps;
}

interface ModalProps {
  showModal: boolean;
}

export default function ModalComponent(props: {
  item: DetailProps;
  showModal: ModalProps;
}) {
  const { item, showModal } = props;
  const modal_order = () => {
    return (
      <Modal
        className={styles.modalContainer}
        size="lg"
        show={showModal}
        // onHide={handleModal}
        centered
      >
       
}

this return error

Type 'boolean' is not assignable to type 'ModalProps'.

anything wrong with my ModalProps? i'm newbie on typescript. i stuck on this error when try to make a reusable component in react typescript

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Since the way you have defined types of props, you need to provide the props like below.

<Modal item={{item: dataDetail}} showModal={{showModal: false}} />

OR

Organize the interfaces like below.

  1. Remove DetailProps interface
  2. Change the ModalProps to the following form
interface ModalProps {
  item: ItemProps;
  showModal: boolean;
}
  1. Define ModalProps as the prop type
export default function ModalComponent(props: ModalProps)
  1. In Order.tsx
<Modal item={dataDetail} showModal={false} />
about 4 years ago · Juan Pablo Isaza Denunciar

0

you are passing boolean to showModal, but it expects an object with showModal property. You have to change the type.

Suggestion/Good practice. : Use React.FC<Props> for component type.

interface ModalProps {
  item: ItemProps;
  showModal: boolean;
}

export default const  ModalComponent: React.FC<ModalProps> = (props)=>{};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda