I'm writing a React component which can forward ref to its chilren
I found out that for the return type of the function components, I can use ForwardRefExoticComponent and ForwardRefRenderFunction. But I'm not sure whats the difference between them.
So far, When using ForwardRefExoticComponent, I can extend it while the ForwardRefRenderFunction cannot? I posted a question related to my case here : How to export forwardRef with ForwardRefRenderFunction
If anyone know whats the difference between them and what they do please help me. Because it seems that React team has no document about them (but they are inside react package)
ForwardRefExoticComponent
The definition taken from here is
If you write it out you get
ForwardRefRenderFunction
The definition taken from here is
Differences
ForwardRefRenderFunction
does not supportpropTypes
anddefaultProps
, whereasForwardRefExoticComponent
does.ForwardRefExoticComponent
has an additional member$$typeof
of typesymbol
ForwardRefRenderFunction
takes aprops
object, which must include a memberchildren
and a ref object as parameters, whereas the call signature ofForwardRefExoticComponent
only takes a props object of arbitrary shape as parameter.Some more thoughts
The interplay of those two definitions is best seen in the definition of the
forwardRef
function:Also, a big difference between the two definitions seems to be, that
ForwardRefExoticComponent
(like all exotic components) are no function components, but actually just objects, which are treated specially when rendering them. Therefore the commentAnd for some reason, those exotic components are necessary in some places.