feat: warn ref usage on functional components

This commit is contained in:
Evan You 2019-11-02 21:33:37 -04:00
parent a651fc44f6
commit 7f054782ad

View File

@ -804,6 +804,14 @@ export function createRenderer<
} }
} }
if (n2.ref !== null && parentComponent !== null) { if (n2.ref !== null && parentComponent !== null) {
if (__DEV__ && !(n2.shapeFlag & ShapeFlags.STATEFUL_COMPONENT)) {
pushWarningContext(n2)
warn(
`Functional components do not support "ref" because they do not ` +
`have instances.`
)
popWarningContext()
}
setRef(n2.ref, n1 && n1.ref, parentComponent, n2.component!.renderProxy) setRef(n2.ref, n1 && n1.ref, parentComponent, n2.component!.renderProxy)
} }
} }