基于react。hooks实现一个简易版的modal

190 阅读1分钟
import React, { Fragment } from "react";
import "./index.scss";
import * as ReactDOM from "react-dom";

interface Props {
  visible?: boolean;
  onClose?: () => void;
  children?: any;
}

const Modal = ({ visible, onClose, children }: Props) => {
  return (
    visible &&
    ReactDOM.createPortal(
      <Fragment>
        <div className={"modal-wrap"}>
          <div>{children}</div>
        </div>
      </Fragment>,
      document.body
    )
  );
};

export default Modal;