Use: useImperativeHandle, useRef
- Child component: useImperativeHandle
`import { useImperativeHandle } from ‘react’; useImperativeHandle(props.cRef, () => ({ getTeams: () => teams, }));
`
import { useImperativeHandle } from 'react'; UseImperativeHandle (props. CRef, () => ({getTeams: () => Teams, () => {// Method setTeams([])}}));Copy the code
- Parent component: useRef
import { useRef } from 'react'; const teamRef = useRef(); const teams = teamRef.current.getTeams(); <Teams id={currentId} Teams ={Teams} cRef={teamRef} />Copy the code