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.

Things to learn in React before using Redux

370 pointsby callumlockealmost 8 years ago

10 comments

k__almost 8 years ago
My first project with React was a mess, mostly because of Redux. Not because it&#x27;s bad, but because the lead dev was adamant about using something Flux like. First we had Flummox, than he rewrote everything in a week with Redux, that was 2 years ago, before Redux had sane async helpers.<p>In my current project (where I&#x27;m the lead, haha) I&#x27;m trying to got state&#x2F;props all the way.<p>I think for most apps it&#x27;s more than enough AND it&#x27;s easier to get started for new devs.<p>React is really easy. I mean coming from Ember and ExtJS, its API is a walk in the park and you can get really far without extra state management.<p>One thing that is important for this approach, minimize nesting.<p>You don&#x27;t want to pass down everything from the app, to the screen, to the list, to the item. etc.<p>Instead of doing:<p><pre><code> &lt;List items={items} &#x2F;&gt; </code></pre> do it like that<p><pre><code> &lt;List&gt; {items.map(i =&gt; &lt;Item item={i}&#x2F;&gt;)} &lt;&#x2F;List&gt; </code></pre> No nesting of screens (top-level components), no (hidden) nesting of components. This may seem kinda strange, because the first example has no dependency to the Item component, but it gives the component that uses the List direct access, which simplifies props-passing immensely.<p>This doesn&#x27;t work for all apps, but it&#x27;s a good starting point.<p>I ended up with 2 folders, screens and components, that are both simply flat lists of component files.
评论 #14813471 未加载
评论 #14812262 未加载
评论 #14813652 未加载
评论 #14813092 未加载
评论 #14813348 未加载
评论 #14824008 未加载
评论 #14812552 未加载
spinlockalmost 8 years ago
I&#x27;d rather use Redux without React than React without Redux. Sure there&#x27;s some boilerplate but we use typescript so the redux boilerplate seems trivial in comparison.<p>Redux keeps your app _simple_. That&#x27;s not the same as easy. It means that you can reason about your app as it grows and new features are added. When you run into problems like: this page is taking too long to load because we do calculations x, y and z on the server to push the data to the app. But z takes forever to compute and makes the initial page load painful. With Redux, you can move z to an async endpoint and just load x and y on page load (put the component that needs z in a loading state). Then, fire an ajax request when the component mounts to get z. When that call returns, it updates your store and the component that needs z transitions from loading to loaded.<p>I took me a couple of hours to do the above in a Redux app and decrease the page load from 2 seconds to 300ms. And it didn&#x27;t add complexity to the app that would make it difficult to maintain. I don&#x27;t even want to think how long that refactor would take if the state had been managed with React.<p>And ... don&#x27;t even get me started on how easy -- and fast -- it is to test a Redux app. Zero side-effects means zero setup and teardown between specs.
sghiassyalmost 8 years ago
The rush to use Redux for every React project is one of the most annoying parts of the React community; using a tool just to use it, before understanding if you need it or not. This article summarizes a lot of good points.
评论 #14812920 未加载
评论 #14813371 未加载
评论 #14815833 未加载
acemarkealmost 8 years ago
As usual, this is an excellent article by Robin. Well-written, and full of great information.<p>It&#x27;s worth noting that both the React and Redux teams (including Dan Abramov and myself) agree that you should focus on learning React first, and _then_ learn Redux. That way there&#x27;s fewer new concepts and terms to learn at once, and once you understand React, you&#x27;ll have a better appreciation for what kinds of problems Redux can help solve. That&#x27;s not to say you _can&#x27;t_ learn them both at once, just that it&#x27;s the suggested approach that will work best for most people.
hippichalmost 8 years ago
As a general rule do not use `this.react` inside `setState({ ... })` - this will cause you problems eventually due state updates being async.<p>If you need to use state to set new state, use functional callback instead - <a href="https:&#x2F;&#x2F;facebook.github.io&#x2F;react&#x2F;docs&#x2F;react-component.html#setstate" rel="nofollow">https:&#x2F;&#x2F;facebook.github.io&#x2F;react&#x2F;docs&#x2F;react-component.html#s...</a>
tchaffeealmost 8 years ago
Worth a read. It summarizes in one place much of what I learned bit by bit from various other articles.
captainmuonalmost 8 years ago
I wish React would come with a standard way to handle Ajax (or a convention or semi-standard library would emerge). <i>(Edit: &quot;comes along&quot; in the sense that immutability-helpers, redux and create-react-app come along with react. I&#x27;m not proposing to add anything to the react module. I&#x27;m not the world&#x27;s best expert on react, but before downvoting can you please assume I know a little bit of what I&#x27;m talking about?)</i><p>Something that:<p>- Can fetch JSON according to criteria from an API<p>- Caches stuff locally (just in memory, or in local storage) in case of duplicate calls<p>- Deals with multiple concurrent calls, and merge them (e.g. fetching 1 and then 2,3,4 before 1 finishes -&gt; either cancel 1, or wait until it finishes, and then fetch only the last requested item.<p>- And all the stuff I can&#x27;t think about right now, like cancellation and timeouts<p>Plug your pure component into one of these, tell it about your API, and you&#x27;re done. It&#x27;s really error prone to write these containers yourself. And I think Redux doesn&#x27;t really help much with Ajax.
评论 #14812682 未加载
评论 #14812598 未加载
评论 #14816492 未加载
评论 #14820706 未加载
评论 #14812950 未加载
评论 #14812624 未加载
评论 #14812540 未加载
评论 #14813438 未加载
noncomlalmost 8 years ago
IMHO Redux is a heavy, clunky and awkward practice that is only holding React back.<p>My advice to anyone reading this forum is give MobX a try before deciding to commit to Redux.
评论 #14815662 未加载
评论 #14816847 未加载
bernadus_edwinalmost 8 years ago
People should learn eventEmitter or PubSub before learn redux
评论 #14814649 未加载
TotallyHumanalmost 8 years ago
I don&#x27;t understand why anyone would use React at all with the ridiculous license.
评论 #14812212 未加载
评论 #14814167 未加载
评论 #14812622 未加载
评论 #14812599 未加载
评论 #14812311 未加载
评论 #14812186 未加载
评论 #14813442 未加载
评论 #14814487 未加载