Warning: Function components cannot be given refs. Attempts to access this ref will fail.

阅读 68

2022-06-06

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

在使用react封装了一个公用组件时,组件中使用了connect连接redux后的组件,然后其他地方引用该组件后就提示以上警告。

解决方法:

导出组件时使用:

export default connect(

stateToProps, null, null, { forwardRef: true }

)(SelectEnumNode);


精彩评论(0)

0 0 举报