简体   繁体   English

呼叫“ redux-saga”的更好方法

[英]Better way of calling 'call' redux-saga

Using the example from react-boiler-plate: 使用react-boiler-plate中的示例:

const response = yield call(() => axios.get(requestURL));

Is there a better way to call axios.get, what if i have axios.post? 有没有更好的方法来调用axios.get,如果我有axios.post怎么办? How can I clean this up a bit without having to do '() =>' just to force it into a function. 我该如何清理一下,而不必执行'()=>'只是将其强制为函数。

Thanks for any advice. 感谢您的任何建议。

If you want to unit test using simple deep equals assertions you could do 如果您想使用简单的深度等于断言进行单元测试,则可以这样做

const response = yield call([axios, 'get'], requestUrl)

const response = yield call([axios, axios.get], requestUrl)

This allows you to avoid creation of anonymous lambda on every call. 这样可以避免在每次调用时创建匿名lambda。

Docs 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM