V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaoming1992
V2EX  ›  推广

一个 react progress 组件

  •  
  •   xiaoming1992 · 2021-04-09 00:00:13 +08:00 · 544 次点击
    这是一个创建于 1113 天前的主题,其中的信息可能已经有所发展或是发生改变。

    当你需要加载很多东西,并想知道整体的加载状态时,可以使用

    ease-progress

    react progress 原始组件, 提供便捷的 progress 统计信息

    import { ProgressProvider, RawProgressContext } from "ease-progress"
    
    function App() {
      const { loaded, total, setProgressState } = useContext(RawProgressContext)
    
      return <>
        {
          LargeAssetList.map((url) => <SomeComponent
            key={url}
            onProgress={(e) => {
              setProgressState({
                [url]: {
                  loaded: e.loaded,
                  total: e.total,
                },
              })
            }}
          />)
        }
    
        <p>loaded: {loaded}</p>
        <p>total: {total}</p>
      </>
    }
    
    ReactDOM.render(
      <ProgressProvider>
        <App />
      </ProgressProvider>,
      document.querySelector("#app"),
    )
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2641 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 15:37 · PVG 23:37 · LAX 08:37 · JFK 11:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.