react中解决异步_在React中管理异步代码

react中解决异步

介绍 (Introduction)

Traditionally, dealing with asynchronous code in React has required some boilerplate:

传统上,在React中处理异步代码需要一些样板:

  • Make a wrapper component to show a pending or rejected state.

    使包装器组件显示挂起拒绝状态。

  • Make our components keeping track of pending and rejected state and inform the wrapper component about state changes.

    让我们的组件跟踪挂起拒绝的状态,并通知包装器组件状态更改。

But ideally, we want:

但理想情况下,我们希望:

  • To care only about the fulfilled state in our components.

    只关心组件中的实现状态。

  • To abstract away the pending and rejected state.

    提取挂起拒绝状态。

Here, I am going to show you how to achieve just that and how to structure asynchronous code in a modern way.

在这里,我将向您展示如何实现这一目标以及如何以现代方式构造异步代码。

工具类 (Tools)

We are going to use the Suspense component and Error Boundaries. They have been available since React 16.6.

我们将使用Suspense组件和Error Boundaries。 从Reac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值