Bootstrap modal in React.js

前端 未结 12 1401
别跟我提以往
别跟我提以往 2020-12-02 07:19

I need to open a Bootstrap Modal from clicking on a button in a Bootstrap navbar and other places (to show data for a component instance, ie. providing \"editing\" f

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 08:07

    You can use the model from the react-bootstrap from link and it's basically a function based

    function Example() {
      const [show, setShow] = useState(false);
      const handleClose = () => setShow(false);
      const handleShow = () => setShow(true);
      return (
        <>
          
    
          
            
              Modal heading
            
            Woohoo, you're reading this text in a modal!
            
              
              
            
          
        
      );
    }
    

    and You can convert it into the class component

    import React, { Component } from "react";
    import { Button, Modal } from "react-bootstrap";
    
    
    export default class exampleextends Component {
      constructor(props) {
        super(props);
        this.state = {
          show: false,
          close: false,
        };
      } 
      render() {
        return (
          
    Delete
    body
    ); } }

提交回复
热议问题