Is there a built-in way to know if a component is already wrapped with React.forwardRef
?
test(React.forwardRef(() => null))
function test(c) {
const isForwardRef = ???
if (!isForwardRef) {
c = React.forwardRef(c)
}
// ...
}
Use the isForwardRef
function from react-is
.
import {isForwardRef} from 'react-is'
isForwardRef(c)
https://github.com/facebook/react/blob/d48dbb824985166ecb7b2959db03090a8593dce0/packages/react-is/src/ReactIs.js#L119-L121
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With