1.子组件使用forwardRef
import React, { forwardRef, useState } from 'react';
function SonTable (props, tableRef) {
const { table_config, data } = props;
return <div ref={tableRef}></div>
}
export default forwardRef(FundTable);
2.父组件
import React, { useEffect, useRef } from 'react';
import SonTable from '../components/SonTable';
export default function Home() {
const sonRef = useRef();
useEffect(() => {
console.log(sonRef )
}, []);
return (
<div>
<SonTable ref={sonRef } props={{}}/>
</div>
)
}