如何在打字稿中使用React-bootstrap模式

问题描述 投票:0回答:1

我正在使用react,react-bootstrap和打字稿。我收到以下错误:

JSX元素类型'Modal'没有任何构造或调用签名。 TS2604

该代码是react-bootstrap网站上的漂亮样板,如果使用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>
    }
}
reactjs typescript react-bootstrap
1个回答
0
投票

有一些问题,所以我希望这对遇到相同问题的所有人有所帮助:

  1. 导入错误,应该是:import { Modal, Button } from 'react-bootstrap';
  2. onHide={() => { this.handleClose() }}
© www.soinside.com 2019 - 2024. All rights reserved.