Reactjs 我想当点击按钮时

Reactjs 我想当点击按钮时,reactjs,react-hooks,bootstrap-modal,Reactjs,React Hooks,Bootstrap Modal,大家好,我是react js的新手,我正在尝试构建一个小型模式应用程序,在这个应用程序中,当我单击trigeer Button时,我想弹出窗口,但我没有使用我的方法,如果有人知道,请告诉我如何解决这个问题 modal.js 这是我的表单,当我点击触发按钮时,我想弹出它 import React, { useState } from 'react'; import './Modal.css'; import Popup from 'reactjs-popup'; import Pop from '

大家好,我是react js的新手,我正在尝试构建一个小型模式应用程序,在这个应用程序中,当我单击trigeer Button时,我想弹出窗口,但我没有使用我的方法,如果有人知道,请告诉我如何解决这个问题

modal.js

这是我的表单,当我点击触发按钮时,我想弹出它

import React, { useState } from 'react';
import './Modal.css';
import Popup from 'reactjs-popup';
import Pop from './Pop';

const Modal = () => {

    const [mail, setEmail] = useState('');
    const [password, setPassword] = useState('');

    const handleChange = (e) => {
        e.preventDefault();
        if (password === "") {
            return alert("please Enter Email and Password")
        }
        else {
            return <Popup trigger={
                <Pop />
            }>
            </Popup>

        }

    }


    return (
        <div>
            <form>
                <div class="form-group">
                    <label for="exampleInputEmail1">Email address</label>
                    <input type="email"
                        class="form-control"
                        id="exampleInputEmail1"
                        aria-describedby="emailHelp"
                        placeholder="Enter email"
                        value={mail}
                        onChange={(e) => setEmail(e.target.value)}
                        required />
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">Password</label>
                    <input type="password"
                        class="form-control"
                        id="exampleInputPassword1"
                        placeholder="Password"
                        value={password}
                        onChange={(e) => setPassword(e.target.value)}
                        required />
                </div>
                <button type="submit" class="btn btn-primary" onClick={handleChange}>Trigger</button>
            </form>
        </div>
    )
}

export default Modal;
import React,{useState}来自“React”;
导入“/Modal.css”;
从“reactjs Popup”导入弹出窗口;
从“/Pop”导入Pop;
常量模态=()=>{
const[mail,setEmail]=useState(“”);
const[password,setPassword]=useState(“”);
常数handleChange=(e)=>{
e、 预防默认值();
如果(密码==“”){
返回警报(“请输入电子邮件和密码”)
}
否则{
返回
}
}
返回(
电子邮件地址
setEmail(e.target.value)}
必需的/>
密码
setPassword(e.target.value)}
必需的/>
触发
)
}
导出默认模式;
pop.js

从“React”导入React
常量弹出=()=>{
返回(
提交
情态标题
&时代;
接近
保存更改
)
}
导出默认弹出窗口;

您可以在此处使用react引导模式组件

import React, {useState, setShow } from 'react'
import {Modal} from 'react-bootstrap';


const myModal = () => {

    //handeling the modal open & close
    const [show, setShow] = useState(false);
    const handleShow = () => setShow(true);
    const handleClose = () => setShow(false);


   

    return (
       
        <>
            //this the button that triggers the modal
            <button onClick={handleShow}> Show Modal </button>

        

            <Modal className="my-modal" show={show} onHide={handleClose}>

                <Modal.Header closeButton className="mymodal-head">
                    <Modal.Title className="mymodal-title"><h4>The Modal</h4></Modal.Title>

                </Modal.Header>

                <Modal.Body className="mymodal-body">
//add your input fields and labels here
                    <input/>
                </Modal.Body>

                <Modal.Footer className="mymodal-footer">
//add your submit button here
                    <button> submit </button>
                </Modal.Footer>

            </Modal>


            
        </>
  
    )
}
import React,{useState,setShow}来自“React”
从'react bootstrap'导入{Modal};
常量myModal=()=>{
//处理模式打开和关闭
const[show,setShow]=useState(false);
常量handleShow=()=>setShow(true);
const handleClose=()=>setShow(false);
返回(
//此按钮是触发模式的按钮
显示模态
模态
//在此处添加输入字段和标签
//在此处添加提交按钮
提交
)
}

希望这有帮助!如果您对模式有任何问题,请随时询问我:)

您可以在此处使用react引导模式组件

import React, {useState, setShow } from 'react'
import {Modal} from 'react-bootstrap';


const myModal = () => {

    //handeling the modal open & close
    const [show, setShow] = useState(false);
    const handleShow = () => setShow(true);
    const handleClose = () => setShow(false);


   

    return (
       
        <>
            //this the button that triggers the modal
            <button onClick={handleShow}> Show Modal </button>

        

            <Modal className="my-modal" show={show} onHide={handleClose}>

                <Modal.Header closeButton className="mymodal-head">
                    <Modal.Title className="mymodal-title"><h4>The Modal</h4></Modal.Title>

                </Modal.Header>

                <Modal.Body className="mymodal-body">
//add your input fields and labels here
                    <input/>
                </Modal.Body>

                <Modal.Footer className="mymodal-footer">
//add your submit button here
                    <button> submit </button>
                </Modal.Footer>

            </Modal>


            
        </>
  
    )
}
import React,{useState,setShow}来自“React”
从'react bootstrap'导入{Modal};
常量myModal=()=>{
//处理模式打开和关闭
const[show,setShow]=useState(false);
常量handleShow=()=>setShow(true);
const handleClose=()=>setShow(false);
返回(
//此按钮是触发模式的按钮
显示模态
模态
//在此处添加输入字段和标签
//在此处添加提交按钮
提交
)
}

希望这有帮助!如果您对模式有任何问题,请随时询问我:)

也许此链接可以帮助您也许此链接可以帮助您