dispatch作用 react_【已解决】React中什么是side effect 副作用

之前学习React 期间,就看到很多地方提到 side effect 副作用

搞得以为是类似于药物💊的副作用呢

后来看到:

大概有点感觉了:

就是额外带的一些效果和作用

但是不是完全理解

所以去找找解释

react what is side effect

“What is a side-effect?

The natural Redux flow is this: some action is dispatched, and as a consequence, some state is changed.

If all your Redux app could do was just to change state as the user played with it, though, would your app be particularly useful? Probably not.

Most apps need to reach out to the outside world to be useful — whether by talking to the server, accessing local storage, recording analytics events, or something else entirely.

That process of calling into the real world is what side-effects are. They are a way of bridging the pure Redux world with the outside world.

Common features of side-effects

Side-effects can happen in response to Redux actions. For example, when a user clicks “Save,” you may want to fire off an AJAX request.

Side-effects may dispatch Redux actions. Like when the save process finishes successfully, you may want to dispatch SAVE_SUCCEEDED; or when it failed, SAVE_FAILED.

They also may not dispatch anything. Some side-effects don’t need to dispatch anything: if you are doing analytics tracking based on Redux actions, you would track things in response to Redux actions, but you will not dispatch anything.”

“React+Flux more complicated processes involving coordination of action creators and side-effects are hard to handle. ”

“side effects (i.e. asynchronous things like data fetching and impure things like accessing the browser cache) ”

【总结】

side effect副作用是:和真实的世界进行交互的方式,就叫做 side effect。

比如:

用户点击了 保存 按钮,然后会异步地调用服务器的接口去保存数据。

(对于redux来说,当保存的过程完成后,根据保存结果而分发SAVE_SUCCEEDED或SAVE_FAILED事件)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值