Use: useImperativeHandle, useRef

  1. 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
  1. 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