是否有必要将所有请求保留在SAGA中,或者您可以为与Redux和Saga无关的请求提供单独的模块?
据我了解,如果我们使用Redux-Saga提出请求,则响应将存储到Redux Store中。但是将所有东西存储在Redux商店中是一种不好的做法。那么,可以使用API请求创建单独的模块并在您不想将响应放入Redux Store中使用它们吗? 我会感谢有关此主题的文章(我自己找不到它)。
As I understand if we make a request by using redux-saga, the response is going to be stored into the redux store. But it is a bad practice to store all the stuff in the redux store. So is it ok to create separate module with API requests and use them when you do not want to put response in redux store ?
I would appreciate articles on this topic (couldn't find it on my own).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在某些情况下,在文件中提出请求是完全可以的。只需仔细进行操作,以防止干扰应用程序性能(如果组件是多次渲染的,并且您只需要一个请求,则在父母中进行等
) react docs 有一个API调用的示例示例Bellow)。现在,我建议您也使用服务来抽象提取逻辑,但是这个想法已经存在,尽管这种情况不应该发生很多,但如果您只需要一些数据,我就不会看到任何理由避免这种情况在特定组件中,将其保存到州没有用。
编辑:
您有 runsaga
因此,您真的不需要另一个库。关于架构问题,这是我试图与React Docs强调的。我不知道是否有此方向的任何文章(在快速搜索中,我也找不到任何文章),但是我认为,对于大多数数据,您希望还原器可以防止不必要的重新加载相同的数据。
但是,没有任何建议,据我所知(文档,文章等)都不要这样做。此外,在某些情况下,这可能是一件好事,没有任何文档建议否则证明这一方向是IMO的事实。
PS:还讨论有关使用redux 的讨论
Making requests in a file is totally fine in some cases. Just do it carefully in order to prevent interfering with app performance (if a component is rendered multiple time and you need just one request do it in the parent, etc.)
As for articles I couldn't find any to exactly this topic, but react docs have an example of api calls (please ignore the class one and check the hook example bellow). Now I would recommend you too use a service for this to abstract the fetch logic, but the idea is there and, while this cases shouldn't happen a lot, I don't see any reason to avoid this if you only need some data in a specific component and there is no use in saving it to the state .
EDIT:
You have runSaga which according to docs
So you don't really need another library. Regarding the architectural problem this is what I was trying to emphasis with the react docs. I don't know if there are any articles in this direction (on a quick search I couldn't find any either), but I think for most of the data you want a reducer to prevent unnecessary reloading of the same data.
However there isn't anything suggesting not to do it as far as I know (neither in docs, articles, etc.). Moreover, in some cases, this can a good thing, and the fact that no docs suggest otherwise is a prove in this direction IMO.
PS: Also a discussion about using saga without redux here