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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How to optimize React applications that use Redux

130 点作者 juliankrispel将近 8 年前

5 条评论

noncoml将近 8 年前
I never understood why Redux became so popular.<p>It basically tries to enforces a few old ideas, pure functions, message passing and immutability, with no help from the language, which results in verbose and ugly code.<p>`a.b = c` becomes `Object.assign({}, a, { b = c })`<p>and<p>`object.method(data)` becomes `store.dispatch({type: METHOD, data})` with the implementation code of the &quot;object&quot; being a huge &quot;switch&quot; statement.<p>If you want immutability, pure functions and message passing, then why not use a language that is build around them and make your life easier? Clojurescript maybe?<p>Also having a single store for all your data, definitely doesn&#x27;t help with speed as a single event suddenly becomes an O(LogN) operation in the best case.
评论 #14706790 未加载
评论 #14706985 未加载
评论 #14709250 未加载
评论 #14707760 未加载
评论 #14706800 未加载
评论 #14708163 未加载
评论 #14706798 未加载
评论 #14709267 未加载
acemarke将近 8 年前
Pretty good summary of the main points for good React-Redux performance. I will say that I&#x27;m not a fan of writing `mapState` functions inline in `connect`, as it makes it harder to read them (especially with that parameter destructuring in those examples). But, good post. I frequently see people ask what&#x27;s wrong with just connecting the top-most component, and you&#x27;ve captured the main reasons why that&#x27;s bad for perf. And yes, you absolutely should use memoized selectors in your `mapState` functions.<p>If anyone&#x27;s interested, I discussed related aspects of good Redux performance in my blog post &quot;Practical Redux, Part 6: Connected Lists, Forms, and Performance&quot; [0], and have a lot of other articles on both React and Redux performance topics in my links list at [1]. Also, my post &quot;Practical Redux, Part 7: Form Change Handling&quot; [2] specifically shows off a React component I built to buffer change events from text inputs to help improve UI performance.<p>[0] <a href="http:&#x2F;&#x2F;blog.isquaredsoftware.com&#x2F;2017&#x2F;01&#x2F;practical-redux-part-6-connected-lists-forms-and-performance&#x2F;" rel="nofollow">http:&#x2F;&#x2F;blog.isquaredsoftware.com&#x2F;2017&#x2F;01&#x2F;practical-redux-par...</a><p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;markerikson&#x2F;react-redux-links&#x2F;blob&#x2F;master&#x2F;react-performance.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;markerikson&#x2F;react-redux-links&#x2F;blob&#x2F;master...</a><p>[2] <a href="http:&#x2F;&#x2F;blog.isquaredsoftware.com&#x2F;2017&#x2F;01&#x2F;practical-redux-part-7-forms-editing-reducers&#x2F;" rel="nofollow">http:&#x2F;&#x2F;blog.isquaredsoftware.com&#x2F;2017&#x2F;01&#x2F;practical-redux-par...</a>
评论 #14707136 未加载
msoad将近 8 年前
I switched to MobX and can&#x27;t be happier. Performance is never a problem and everything is just simpler and easier to understand. I think you should give MobX a shot.
评论 #14707664 未加载
评论 #14706844 未加载
评论 #14707183 未加载
评论 #14707076 未加载
评论 #14707953 未加载
dsun179将近 8 年前
A few months ago I read the the article from the redux-creator who sais that you should only use redux if you really need it. I found out that most of my trubbles came from the fact that I should not have used redux. I lately removed it and am now using rxdb for things that have to be state-like and persistent. For everything else I just use reacts setState on the plain components.
评论 #14707107 未加载
mparr4将近 8 年前
I&#x27;ve not heard anyone complain about Redux&#x27;s performance. Do folks consider it slow?<p>If so, what about it is slow? And slower than what?
评论 #14707097 未加载
评论 #14708804 未加载
评论 #14707090 未加载