Function components cannot be given refs.

Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

问题描述:
在Antd Form 组件中使用自定义 Function component时提示以上警告错误。

解决办法:
使用 forwardRef 包裹函数组件

import React, { forwardRef } from 'react';
const MyFunctionComponent = forwardRef((props, _ref) => {
	return <div> something here ......</div>
}

版权声明:本文为u012359704原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。