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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

React Considered Harmful

1 点作者 lupin_sansei将近 5 年前

1 comment

testbot123将近 5 年前
This is somewhat disingenuous. They give the simple example below:<p><pre><code> $(&quot;.fooButton&quot;).click(function() { $.ajax(&quot;&#x2F;update-foos&quot;, { method: &quot;POST&quot; }); }); </code></pre> and then give the &quot;same&quot; example the React treatment, which not only includes third party libraries for fetching, but also managing fetch state, storing data, and connecting to the store, which none of the above does.<p>A better version of React doing the above would be:<p><pre><code> export function FetchDataButton ({ ...buttonProps }) { const fetchData = useCallback(() =&gt; fetch(&#x27;&#x2F;update-foos&#x27;, {method: &#x27;POST&#x27;}), []) &#x2F;&#x2F; prop drilling for this example only. don&#x27;t do this normally. return &lt;button {...buttonProps} onClick={fetchData} &#x2F;&gt; } </code></pre> which does exactly what the initial example does, additionally rendering the actual button, built-in DOM reconciliation, a declarative API, built-in reactivity (meaning you don&#x27;t have to handle figuring out what gets updated in response to new data), etc etc.<p>Yes, React introduces boilerplate but not as much as this post makes out, and certainly not enough to warrant the &quot;considered harmful&quot; label.<p>&gt; We — all of us — are not mature enough yet for abstractions like React.<p>Not quite. <i>You</i> aren&#x27;t ready because you haven&#x27;t learned the basic concepts enough to understand the problems that React is solving.