Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!