[英]use state if i'm using redux
if I'm using redux and redux saga to manage state but a lot of times I wanna do API request for something and I need the result only at this component is it ok to just use state? 如果我使用redux和redux saga来管理状态,但是很多时候我想对某些东西进行API请求,而我只需要在此组件上使用结果就可以使用状态吗? or this considered a bad practice because the idea behind redux is that all the states should be in one place
或这被认为是不好的做法,因为redux背后的想法是所有州都应该在一个地方
In my opinion, it is fine to do it in certain situations. 我认为,在某些情况下可以这样做。 However, you need to be aware of a situation when the request is pending and the user already navigated to a different page of your app.
但是,您需要注意一种情况,即请求待处理并且用户已经导航到应用程序的其他页面。 When a request comes back it will try to do
this.setState
on unmounted component! 当请求返回时,它将尝试在未安装的组件上执行
this.setState
!
So I think is that you should trust your instincts on this one :) 所以我认为您应该相信自己的直觉:)
You probably have already seen it, but I will share it anyway. 您可能已经看过了,但是无论如何我都会分享。 You might not need redux.
您可能不需要redux。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.