0

I am using react, react-bootstrap and typescript. I get the following error:

JSX element type 'Modal' does not have any construct or call signatures. TS2604

The code is pretty boilerplate from the react-bootstrap website which works if I use javascript:

import React, { Component } from "react";
import Modal from 'react-bootstrap';

class InfoModal extends Component{
    state = { show: true }

    render(){
     <Modal show={show} onHide={handleClose}>
        <Modal.Header closeButton>
          <Modal.Title>Modal heading</Modal.Title>
        </Modal.Header>
        <Modal.Body>Woohoo, you're reading this text in a modal! 
        </Modal.Body>
        <Modal.Footer>
          <Button variant="secondary" onClick={handleClose}>
            Close
          </Button>
        </Modal.Footer>
      </Modal>
    }
}

1 Answer 1

2

There were a few issues so I hope this helps anyone with the same issue:

  1. The import was wrong it should have been: import { Modal, Button } from 'react-bootstrap';
  2. onHide={() => { this.handleClose() }}
Sign up to request clarification or add additional context in comments.

1 Comment

Would be nice to add ModalProps or have the component props type extend it so one can leverage all the other props that come with the Modal component

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.