4 ms·
> 5. Use Redux.js Well, that is not really something every React.js beginner should know. Feels weird to say that a X beginner should learn framework Y since h
by diggan 11y ago
> 5. Use Redux.js
Well, that is not really something every React.js beginner should know. Feels weird to say that a X beginner should learn framework Y since he is probably just interested in X...
> 6. Always use propTypes
Worth mentioning that this slows down your application since React needs to check all the props. Don't forget to set NODE_ENV=production when compiling your production script.
- awjr 11y agoIf you are learning MVC, only learning V is not going to get you far. I do wonder if things like Typescript can solve a lot of the speed issues.
- EvanPlaice 11y agoWhy would you assume Typescript solves any speed issues? Typescript's type checking adds overhead just the same. So it's also a good idea to disable checks during runtime.
- tlrobinson 11y agoTypeScript doesn't do any runtime checks, AFAIK. In fact, that's one of their stated goals: "Impose no runtime overhead on emitted programs." https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals https://github.com/Microsoft/TypeScript/wiki/TypeScript-Desi...
- EvanPlaice 11y agoTo-may-to, to-mah-to. That doesn't answer what I was asking. Fact: type checking is disabled during runtime. Why would one assume that Typescript somehow solves speed issues? It has no measurable impact on runtime performance.
- tlrobinson 11y agoI was addressing the second part of your comment. TypeScript is a static type checker. It operates at compile time. There is nothing to "disable" at runtime. But yes, regarding your original question, you are correct, aggressive optimization is a non-goal of TypeScript. It won't improve performance.
- diggan 11y agoWell, if you set out to learn React (which this article is about), you are only learning React. Not even V in MVC because probably you're not out after learning MVC. You're out after learning React.
- rootlocus 11y agoYou're not learning MVC, you're learning React. For example: I'm not learning software development, I'm only learning javascript. I don't want to also learn sql so I can make the backend storage.
- davnicwil 11y agoYou're absolutely right - the power and benefits of libraries like Redux are so obvious once you've grokked React but as a beginner it really is just going to slow you down or just get in the way of learning. This is partly because of the overhead of having to learn another library, and partly because you have to learn by making mistakes, experiencing the pain, and then badly hand-implementing parts of Redux yourself to truly understand its value, and how it should be used. At that point you're way beyond beginner level. Same goes for '8. Use JSX, ES6, Babel, Webpack, and NPM' - JSX aside, setting up this tool stack is totally unnecessary for a beginner getting started hacking on a Hello World app. This is something you do after you've learned React, and you want to use use it in a 'real' project. Depending on your knowledge of these tools it could take literally days of work to get started. I'll be honest, if someone with no knowledge of React asked me how to get into it, I'd also be tempted to mention Redux or Relay, the tool stack, all those things in the React ecosystem that are fantastic and essential for a real production React stack. But it's just too much information, it's not what a beginner wants or needs to know. I think there's a general lesson here - learning frameworks, how they fit together, and what tooling to use is really complicated and only seems 'obvious' once you have the big picture. You have to remember what it felt like when you were a beginner, and just wanted to learn the basic rudiments of React itself - that's more than complicated enough to get started with. When giving advice to beginners, it needs to be laser-focused, ignoring everything but the exact thing they're interested in learning. Forget about all the extra stuff they'll need in the 'real world' - they'll figure that out along the way anyway.
- mikeryan 11y agoSame goes for '8. Use JSX, ES6, Babel, Webpack, and NPM' - JSX aside, setting up this tool stack is totally unnecessary for a beginner getting started hacking on a Hello World app. While I agree with you in theory, in practice learning how to use Babel/JSX and probably es6 are pretty essential to react. All the tutorials are written using JSX which necessitates a transpiler. And a ton of the supporting libraries are now in es6. If you are going to use react you're really going to need to figure out the es6 tool chain.
- davnicwil 11y ago
- kderbe 11y agoNeither this comment nor the article clearly spell this out: when you use the production version of React, much of the developer-assisting error checking is removed (not just propTypes[1], but many other error checks[2]), so you don't need to worry about the end-user performance impact of propTypes. As an example of how much this helps, one React-heavy page of mine dropped from 1500ms to 300ms by switching versions, according to my browser profiler. [1] https://facebook.github.io/react/docs/reusable-components.html#prop-validation https://facebook.github.io/react/docs/reusable-components.ht... [2] https://facebook.github.io/react/downloads.html#development-vs.-production-builds https://facebook.github.io/react/downloads.html#development-...
- davnicwil 11y agoOP is talking about compiling react in prod mode yourself, having pulled the source as an npm dependency, as opposed to pulling in the pre-built prod version with a script tag. See the npm section right below the Individual Downloads section you've linked to in [2] - this is the recommended, and more common, way to use react.