import { jsx, jsxs, Fragment } from 'solid-jsx/jsx-runtime';

/*@jsxRuntime automatic @jsxImportSource solid-jsx*/
const toc = [];
function _createMdxContent(props) {
  const _components = Object.assign({
    p: "p",
    code: "code",
    pre: "pre",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsx(_components.p, {
      children: "Suspense 允许我们在加载数据时显示回退内容。在初始化加载时非常有用，但在后续导航中，回退到骨架屏通常是更糟糕的用户体验。"
    }), "\n", jsxs(_components.p, {
      children: ["我们可以通过使用 ", jsx(_components.code, {
        children: "useTransition"
      }), " 来避免回到回退状态。", jsx(_components.code, {
        children: "useTransition"
      }), " 提供了一个包装器和一个加载的指示器。包装器将所有下游更新放在一个事务中，该事务在所有异步事件完成之前不会提交。"]
    }), "\n", jsxs(_components.p, {
      children: ["这意味着当控制流暂停时，它会在离屏渲染时继续显示当前分支。现有边界下的资源读取会被添加到过渡(transition)中。但是，任何新的嵌套 ", jsx(_components.code, {
        children: "Suspense"
      }), " 组件如果在进入视图之前尚未完成加载，则会显示回退内容。"]
    }), "\n", jsxs(_components.p, {
      children: ["请注意，当你在示例中进行导航操作时，我们不断看到内容消失回退加载占位。让我们在 App 组件中添加一个过渡。首先，我们需要替换 ", jsx(_components.code, {
        children: "updateTab"
      }), " 函数。"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " [pending, start] = ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "useTransition"
        }), "();\n", jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "updateTab"
        }), " = (", jsx(_components.span, {
          className: "hljs-params",
          children: "index"
        }), ") => ", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "start"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setTab"
        }), "(index));\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: [jsx(_components.code, {
        children: "useTransition"
      }), " 返回一个挂起的信号指示器和一个开始过渡(transition)的方法，这两个返回值囊括了我们的状态更新。"]
    }), "\n", jsx(_components.p, {
      children: "我们应该使用表示挂起状态的 Signal 在 UI 中添加一个状态指示器。可以在选项卡容器 div 上 添加一个表示挂起的 class："
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: ["<div ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "class"
        }), "=", jsx(_components.span, {
          className: "hljs-string",
          children: "\"tab\""
        }), " classList={{ ", jsx(_components.span, {
          className: "hljs-attr",
          children: "pending"
        }), ": ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "pending"
        }), "() }}>\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "有了这些代码，我们的标签切换应该会更加流畅。"
    })]
  });
}
function MDXContent(props = {}) {
  const {wrapper: MDXLayout} = props.components || ({});
  return MDXLayout ? jsx(MDXLayout, Object.assign({}, props, {
    children: jsx(_createMdxContent, props)
  })) : _createMdxContent(props);
}

export { MDXContent as default, toc };
//# sourceMappingURL=lesson-9dc1aa7e.js.map
