React - passing refs as a prop

后端 未结 2 636
夕颜
夕颜 2021-02-06 08:07

I am trying to manage a checkbox with react. The following code works well enough, but I want to refactor out the code in the render method so that it uses a Component. I want

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 08:42

    Use createRef to create the ref that you end up passing down.

    If you're passing a ref to a function component use React.forwardRef.

    If you're passing a ref down to a class component ensure that the prop name is anything except ref or you'll get a special prop warning.

提交回复
热议问题