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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Am I Overreacting? Or is React Over-Reacting?

3 点作者 devtailz超过 2 年前

1 comment

acemarke超过 2 年前
Seems like most of the issues here are caused by an incomplete understanding of how React rendering actually works.<p>That&#x27;s why I wrote an incredibly extensive article on this: &quot;A (Mostly) Complete Guide to React Rendering Behavior&quot;. I&#x27;d strongly recommend reading through that to help internalize what React is doing and how re-rendering works:<p>- <a href="https:&#x2F;&#x2F;blog.isquaredsoftware.com&#x2F;2020&#x2F;05&#x2F;blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.isquaredsoftware.com&#x2F;2020&#x2F;05&#x2F;blogged-answers-a-...</a><p>In general: yes, *React re-renders recursively by default*. Also: yeah, _no_ web app will update as efficiently as a 3D game engine, because it&#x27;s under completely different technical constraints. On the other hand, web apps are also a completely different _kind_ of application than a 3D game as well, and the DOM is a different display environment than rendering 3D models and executing physics logic.<p>Also, the article said:<p>&gt; I would like to acknowledge that there should be “some” overhead from using the development build, but I wouldn’t expect turning on production mode would have a substantial impact on this example.<p>There _is_ actually significant difference between dev and prod build performance. By default, profiling only works against development builds, but there&#x27;s two ways you can try measuring the render time of a production build:<p>- Alert your build setup to alias &quot;react-dom&quot; to the special profiling build, which is a production-like build that still has the profiling logic enabled, then use the React DevTools Profiler to repeat this demo: <a href="https:&#x2F;&#x2F;kentcdodds.com&#x2F;blog&#x2F;profile-a-react-app-for-performance#update-the-webpack-config-for-production-profiling" rel="nofollow">https:&#x2F;&#x2F;kentcdodds.com&#x2F;blog&#x2F;profile-a-react-app-for-performa...</a><p>- You can also use the special `&lt;Profiler&gt;` component with a callback that captures and logs render timing data. Off the top of my head I can&#x27;t remember whether it will report data with a true production build, or whether it also requires the &quot;profiling&quot; build. Either way, adding that to your component tree will give you the timings for each render pass, and you can log or do something with that data.<p>Agreed that some of the steps to optimize rendering behavior ( use of `React.memo()` and `useCallback()` ) can be annoying, but you also don&#x27;t _need_ those all the time.<p>In general, React is not designed to be the absolute fastest way to update the UI. It _is_ designed to let you write encapsulated components that are straightforward to understand, and remove the need to think about _how_ the DOM gets updated. In most cases, the update performance _is_ &quot;good enough&quot; out of the box, without needing to do additional work to optimize that, and React does give you tools to improve that where needed.
评论 #34085086 未加载