是否有一种内置的方法可以知道组件是否已经用React.forwardRef
封装?
test(React.forwardRef(() => null))
function test(c) {
const isForwardRef = ???
if (!isForwardRef) {
c = React.forwardRef(c)
}
// ...
}
使用react-is
中的isForwardRef
函数。
import {isForwardRef} from 'react-is'
isForwardRef(c)
https://github.com/facebook/react/blob/d48dbb824985166ecb7b2959db03090a8593dce0/packages/react-is/src/ReactIs.js#L119-L121