import React, { FunctionComponent, useEffect, useRef } from 'react' import { createPortal } from 'react-dom' import { modal } from '../styles' interface IModal { state: [boolean, Function] children?: any } const Modal: FunctionComponent = ({ state, children }) => { const [visible, setVisible] = state const ref = useRef() useEffect(() => { ref.current = document.body }, []) const content = visible ? (
{children}
) : null return ref.current ? createPortal(content, ref.current) : null } export default Modal