Skip to content

Instantly share code, notes, and snippets.

let currentInstance = null  // 缓存当前的vue实例
let isMounting = false      // 初始化挂载 or 更新
let callIndex = 0           // 每个state的唯一标记id

function ensureCurrentInstance() {
  if (!currentInstance) {
    throw new Error(
      `invalid hooks call: hooks can only be called in a function passed to withHooks.`
    )