How to use a react component fetched from an api?

倖福魔咒の 提交于 2019-12-06 19:16:41
Aminadav Glickshtein

By using the newest chrome you can do something like this:

const ProfilePage = React.lazy(() => import(/* webpackIgnore: true */ 'https://api.example.com/profile-page.mjs'));

<Suspense fallback={<div>Please wait for component to be loaded</div>}>
  <ProfilePage />
</Suspense>

ProfilePage will be a lazy component. It will be loaded once the fetch completed. While you wait you will see the fallback.

More info:

It is an experimental features!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!