【问题标题】:React modal is not working when call in function调用函数时反应模式不起作用
【发布时间】:2021-09-22 06:14:13
【问题描述】:

我有一个我想在 useffect 中打开的模态,这是我在 carvin 函数 console.log 中的代码工作,但模态没有弹出。我已经将一个主要组件作为 Loyaltycash 并调用 carvin in useeffect

import React, { useState, useEffect } from "react";
export default function Loyaltychash(props) {
  const { show, handlemodalloyalty, contractid } = props;


  useEffect(() => {
    if (contractid != "") {
      getdata();
      setLoading(true);
      carvin();
    }
  }, [show]);
  


  return (
    <div>
    </div>
  );
}
function carvin() {
  console.log("innnn");
  return (
    <div>
      <div>
        <Modal show={true}>
          <Modal.Header>
            
          </Modal.Header>
          <Modal.Body>
          </Modal.Body>
          <Modal.Footer>
            <Button variant="secondary">Close</Button>
            <Button variant="primary">Save Changes</Button>
          </Modal.Footer>
        </Modal>
      </div>
    </div>
  );
}

【问题讨论】:

    标签: javascript reactjs ecmascript-6 modal-dialog


    【解决方案1】:

    你一直在使用 show={true}

    <Modal show={show}>
    

    return (
        <div>
    {carvin()}
        </div>
      );
    

    【讨论】:

    • 我想打开carvin功能中的open。在 Loyaltychash 中,还有另一种使用 show 处理的模式
    • 你应该调用 carvin 函数来显示
    • 有什么方法可以顶开模态并调用它作为回报
    • return ( &lt;div&gt; {carvin()} &lt;/div&gt; );
    猜你喜欢
    • 2021-11-25
    • 2016-07-19
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多