import React, { useState , useImperativeHandle , forwardRef } from 'react';
const Index: React.FC<Man> = (props ,ref ) => {
const [hasIdCard, setHasIdCard] = useState('1');
useImperativeHandle(ref, () => ({
setHasIdCard: (hasIdCard) => {
setHasIdCard(hasIdCard);
}
}));
return (
<></>
);
};
export default forwardRef(Index);
import React, { useRef , useEffect} from 'react';
import Child from './components/child/index'
const Index: React.FC<{}> = () => {
const ref = useRef<any>();
useEffect(() => {
ref.current.setHasIdCard('1')
}, []);
return <Child ref={ref}/>
}