In the legacy react documentation for ref forwarding, there's a note which says:
Ref forwarding is not limited to DOM components. You can forward refs to class component instances, too.
In another SO post it is suggested that DOM components are those which return a single(non-nested) dom element. E.g.
function FancyButton(props) {
return (
<button className="FancyButton">
//no further child elements
//which means not even {props.children}
</button>
);
}
My doubt is that these plain-single-non-nested(leaf element?) elements can be represented as class components as well, so if react docs mean this as the DOM component, then why would it say You can forward refs to class component instances, too?
To me it feels like react docs meant to say
ref forwarding is not limited to function components. You can forward refs to class component instances, too.
from What are DOM components in the context of refs in react Js?
No comments:
Post a Comment