TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A React.js case study

153 pointsby xngzngover 10 years ago

8 comments

wingspanover 10 years ago
Thanks for putting this together, always interesting to see people use React for the first time! I did a code review of sorts and cleaned up the code to be more idiomatic React. You can find the series of commits with in-depth comments on GitHub [1]. I may even write this up as a blog post on my website [2].<p>In short:<p>- Don&#x27;t pass around components and call methods on them; prefer to pass props instead<p>- Conditional rendering instead of hiding, exactly as [3]<p>- Use the JSX harmony transforms<p>- Declare props<p>- Use classSet<p>- setState only needs to include props that change, rest stay the same<p>[1] <a href="https://github.com/ianobermiller/reactexperiment/commits/" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ianobermiller&#x2F;reactexperiment&#x2F;commits&#x2F;</a><p>[2] <a href="http://ianobermiller.com" rel="nofollow">http:&#x2F;&#x2F;ianobermiller.com</a><p>[3] <a href="https://news.ycombinator.com/item?id=8247422" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8247422</a>
评论 #8249924 未加载
评论 #8248618 未加载
评论 #8248917 未加载
评论 #8249895 未加载
lobster_johnsonover 10 years ago
&gt; I first tried to do this: [...] ...which actually worked, but generated a React error message about an unmounted component.<p>I suspect that you were doing something wrong that triggered this error. Unmounting components based on state is perfectly idiomatic React, and I do it all the time:<p><pre><code> {this.state.mode === &#x27;map&#x27; &amp;&amp; &lt;Map&#x2F;&gt;} </code></pre> You pay for the added DOM work, of course, but this is usually negligible in my experience, especially in your case. You do have to make sure you follow the component lifecycle so that you don&#x27;t try to use getDOMNode() or similar with a component that is not currently mounted.
评论 #8247650 未加载
rdtscover 10 years ago
I see some criticism here but I think it is worth pointing out this looks like a person learning to use a new technology and sharing their experience, which is great.<p>Sometimes that means using non-idiomatic constructs or just having some rough edges. Please be considerate.
illiciumover 10 years ago
I&#x27;m not particularly fond of the way React mixes presentation (returning nodes in render()) and logic. Particularly things like:<p><pre><code> var classes = _.reduce([&quot;flipped&quot;,&quot;correct&quot;,&quot;wrong&quot;],function(m,c){return m+(this.state[c]?c+&quot; &quot;:&quot;&quot;);},&quot;&quot;,this); </code></pre> seem very inelegant compared to say, Angular&#x27;s ngClass, which does the same thing in a data-driven way. But, that&#x27;s not to say Angular is free from template logic either.
评论 #8247590 未加载
评论 #8247584 未加载
评论 #8248130 未加载
评论 #8247658 未加载
ufoover 10 years ago
Why do<p><pre><code> className={this.state.playing ? &quot;hidden&quot; : &quot;showing&quot;} </code></pre> instead of<p><pre><code> &lt;div&gt; {(this.state.playing ? &lt;Board&#x2F;&gt; : &lt;Wordform&#x2F;&gt; )} &lt;&#x2F;div&gt;</code></pre>
评论 #8247937 未加载
评论 #8247700 未加载
评论 #8247562 未加载
krawallerover 10 years ago
There&#x27;s now a follow-up to this post, walking through a refactor based on the comments given here and elsewhere. Thank you all for the feedback!<p><a href="https://news.ycombinator.com/item?id=8273026" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8273026</a>
maccardover 10 years ago
Doesn&#x27;t work properly for me using FF 31.0<p>I can see the words on the tiles before clicking them.
评论 #8247692 未加载
theycallmemortyover 10 years ago
Off-topic: Why do people use lodash over underscore.js?