首页 > 解决方案 > 使用 Modal 框架反应 useRef 钩子

问题描述

我正在学习使用 ReactHooks,需要一些帮助来了解如何将模式的内容分配给 myRef htmlDivElement。

如何将模型的内容分配给 ref 元素。当我执行它时,它是空的,没有任何内容。如何将 Modal 的内容附加到 div 中?

 import React, { FunctionComponent, useRef } from "react";
    import { Modal } from "antd";
    import styles from "./my.module.scss";
    export const myComponent: FunctionComponent= () => {
        const myRef = useRef<HTMLDivElement>(null);
    
            const DivElement = myRef.current
            Display(DivElement);
    return (
        <div ref={myRef} id="graph_div" className={styles.modal}>
        </div>
      );
    };
    const Display = (
        DivElement: HTMLDivElement | null
      ) => {
DivElement.append  // Somehow I need this to append the Model element
      <Modal
        title="Basic Modal"
      >
        <p>Some contents...</p>
        <p>Some contents...</p>
        <p>Some contents...</p>
      </Modal>
    
    };

当它呈现 id=graph_div 时,其中没有任何内容。它是空的。非常感谢

标签: reactjsreact-hooksantd

解决方案


推荐阅读