Typescript RefForwardingComponent not working

后端 未结 4 1653
天命终不由人
天命终不由人 2021-01-19 05:03

I am trying to make my component accept a ref.

I have a component like so:

const MyComponent: RefForwardingCom         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-19 05:18

    Custom function components can't have 'ref' as a prop. You will have to give it a different name. 'yourRef', for example will be inside the props object.

    
    

    So to use the ref prop:

    const MyComponent: RefForwardingComponent = (props) => {
    return 
    Hoopla
    }

    or you can descructure the props:

    const MyComponent: RefForwardingComponent = ({yourRef}) => {
    return 
    Hoopla
    }

提交回复
热议问题