TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

React State vs. Redux State: When and Why?

5 点作者 mattnedrich将近 8 年前

4 条评论

borplk将近 8 年前
Redux state is useful for when other parts of the app need to be aware of or react to that state.<p>Sometimes there are little bits and pieces that may look like they are &quot;private state of a component&quot; but over time you&#x27;ll find instances where it&#x27;s useful to know that state.<p>For example I have a LoginForm component and a SignupForm component.<p>If you have half-way filled email and password on the LoginForm, but click on &quot;Create an account&quot; it would be nice if SignupForm picked up that state from the login form.<p>So my LoginForm state is stored in the redux store under the key &quot;loginForm&quot;.<p>And SignupForm will pick up that state if available and vice-versa for going from sign up to log in.
评论 #14535216 未加载
Philomath将近 8 年前
What I like to do is not use Redux at all until I find I need it. So basically it comes a point in my app when I have too much information in my state and I need to share it with multiple components. At this point, I add the most global stuff to the redux store and keep meaningless things as react state.
hobonumber1将近 8 年前
Use Redux state if you want the data to be available across multiple components.<p>Use React Component State if no other component cares about the data.
fibo将近 8 年前
Use both, React for internal component state, Redux for global state that could be serialized.