import React, { FC, HTMLAttributes, ReactNode, useEffect, useRef, useState } from 'react' interface Size { height: number width: number } interface AutoFullProps extends HTMLAttributes { children(size: Size): ReactNode } const fullStyle = { width: '100%', height: '100%', } const AutoFull: FC = (props) => { const [size, setSize] = useState(null) const ref = useRef(null) useEffect(() => { if (ref.current) { setSize({ height: ref.current.offsetHeight, width: ref.current.offsetWidth, }) } }, []) return ( {size && props.children(size)} ) } export default AutoFull