简体   繁体   English

如果我正在使用redux,请使用state

[英]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.

相关问题 如果我两次使用相同的react / redux组件,它们会共享状态吗? - If I'm using the same react/redux component twice, will they share state? 我可以在使用 Redux 或 Redux 存储时在组件中使用状态吗? - Can I use state in components while using Redux or Redux store? State 更改为未定义值。 我正在使用带有 redux-persist 的 redux-toolkit - State changing to undefined value. I'm using redux-toolkit with redux-persist 为什么我没有通过 redux 获得实际状态? - why I'm not getting the actual state with redux? 从 state 中删除 object 后,组件未重新加载,我正在使用 React-redux - Component isn't reloading after deleting an object from the state, I'm using React-redux Redux状态更改:仅当我在rootPath上时,UI才会更新 - Redux State Change: UI only updates if i'm on rootPath 如何使用redux状态变量进行身份验证 - how to use authentication using redux state variable 当我使用redux时,我是否应始终将响应保持在全局状态,即使结果只使用一次? - When I'm using redux, should I always keep the response in the global state even the result will be used only once? 我正在使用 Redux。 我应该在 Redux 存储中管理受控输入状态还是在组件级别使用 setState? - I am using Redux. Should I manage controlled input state in the Redux store or use setState at the component level? 如何使用 redux-form 更新 redux state - How can i update the redux state using redux-form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM