Browse Source

feat: warn ref usage on functional components

Evan You 6 years ago
parent
commit
7f054782ad
1 changed files with 8 additions and 0 deletions
  1. 8 0
      packages/runtime-core/src/renderer.ts

+ 8 - 0
packages/runtime-core/src/renderer.ts

@@ -804,6 +804,14 @@ export function createRenderer<
       }
     }
     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)
     }
   }