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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Simple Regex Filter with React.js and Immutable-Js

1 点作者 dauoalagio大约 10 年前

1 comment

kentor大约 10 年前
Please don&#x27;t do what&#x27;s written in this article. It&#x27;s an anti-pattern to set state from props[1]. Consider what happens when a new set of data is passed to this component from above, this component won&#x27;t get the new set of data and now it&#x27;s out of sync with the rest of the application.<p>Another problem with what&#x27;s written is that there&#x27;s unnecessary state. In general it&#x27;s best to figure out the <i>minimal</i> set of state needed to render the UI; everything else should be <i>computed</i> on the fly, directly in the render call (or refactored out into methods).<p>In this article, data and filteredData as state is unnecessary! The minimal state needed to describe the UI is the text to filter the data and the data itself which is from props. filteredData should be computed, not stored in state.<p>The text in the input box should always represent the state of the filter text, and the box itself can be used to update this state. This can be achieved with LinkedStateMixin[2].<p>1. <a href="https:&#x2F;&#x2F;facebook.github.io&#x2F;react&#x2F;tips&#x2F;props-in-getInitialState-as-anti-pattern.html" rel="nofollow">https:&#x2F;&#x2F;facebook.github.io&#x2F;react&#x2F;tips&#x2F;props-in-getInitialSta...</a> 2. <a href="https:&#x2F;&#x2F;facebook.github.io&#x2F;react&#x2F;docs&#x2F;two-way-binding-helpers.html" rel="nofollow">https:&#x2F;&#x2F;facebook.github.io&#x2F;react&#x2F;docs&#x2F;two-way-binding-helper...</a>