value of using React.forwardRef vs custom ref prop

后端 未结 2 1751
终归单人心
终归单人心 2020-12-05 02:23

I see that React.forwardRef seems to be the sanctioned way of passing a ref to a child functional component, from the react docs:

const FancyButton = React.f         


        
2条回答
  •  感动是毒
    2020-12-05 02:50

    Ref is a standard property in React components.

    Some components that wrap other components to provide additional functionality, use ref to refer to wrapped component and expect that the component has ref property.

    It is better for a component to have the ref property to be compatible with other components and libraries.

    Function components cannot have the "ref" property and must use forwardRef instead to provide ref property.

提交回复
热议问题