React.forwardRef 获取子组件的dom_html

 

const FancyButton = React.forwardRef((props, ref) => (
<button ref={ref} className="FancyButton">
{props.children}
</button>
));

function LoadingButton() {
const ref = React.createRef();

useEffect(() => {
console.log(ref)
}, [])
return (
<div className="m-test-wrap">
<FancyButton ref={ref}>Click me!</FancyButton>
</div>
);
}