Live data from Hacker News

Things every React.js beginner should know

camjackson.net

161–170 of 247 posts

Re: Things every React.js beginner should know

#161

#3 Write functional components I'd say "Write functional components where it makes sense". For simple components that is a reasonable advise, however in cases when you need such methods as `componentDidUpdate` or generally any lifecycle methods - that won't do and you have to use classes.

Not a React guy, but why couldn't the component that updated broadcast that it did so? Or is that componentDidUpdate method a callback to the message I'm describing?

In addition to what lopatin replied to you - sometimes your component have to subscribe to some window event - for example 'resize'. I'd say it is way better to handle this event attachment/removal within the component instead of inventing some convoluted system of events in the root container which broadcast changes.

There's a number of situations when functional component just not enough.

Re: Things every React.js beginner should know

#162
post #27
post #9

> 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.

If 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.

You'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.

Re: Things every React.js beginner should know

#163
post #154

Great article! As we have been on-boarding developers with React, we noticed that all of the boilerplate needed to get Babel, Webpack, Redux, and a testing environment (we use Mocha, Karma, and Chai) was simply too much for most people to handle while beginning something new. There are lots of boilerplate projects but telling someone new to fork a project on GitHub and start building an app from there was raising som…

Nice, I like this a lot. I think it's the cleanest and most concise approach I've seen re: universal React/Redux. Is there a way to override or extend the webpack config though? (without having to fork it) What if some projects need different loaders or want to use code splitting, etc?

Pro Tip: Open an issue on GitHub for requested features to move them up in priority ;)

Re: Things every React.js beginner should know

#164
post #78

What really bothers me about React (and other frameworks) that without JS you do not see anything. No fallback. No progressive enhancement. Is this really the way to go? Did JS replace HTML/CSS as the backbone of websites/applications ?

I'm with you on this one. Although I use React actively I still have problems with the fact that you won't see content of the app without JS on initial load. Sure, there's a matter of isomorphic applications where React renders content on server during first call, however after trying several times implementing it - just ended up abandoning that idea due to how massively complex various things become in certain cases with authorizations for users and so on.

Re: Things every React.js beginner should know

#165

I'm not a React or Angular expert, but do you really put HTML inside of your JS code? It just bothers me too much. We spent years in early web days learning that code and templates should be separate, yet here we are putting HTML inside of code, which goes against years of practice. Can anyone share their professional thoughts about this?

I found it to be a huge productivity boost. In highly interactive apps, templates and code are connected so much, trying to pretend that they are not and switching back and forth all the time for me personally feels like fooling myself.

Re: Things every React.js beginner should know

#166
post #156
post #148

Earlier quoted context omitted.

Ahh, well I never claimed it was logicless. I claimed the templates were logicless, and they are. The logic is kept separate inside the processors that you bind to the template.

Except the -scope part means that the foreach-ness is indicated by the template, so people consider that to be not-logicless. I understood your claim fine. I'm trying to explain why it might be considered false (and I did already say I consider the arguments each way basically hair splitting).

Interesting, I've never imagined an identifier could be labeled as logic. There is no need for a scope, if you mean that the outer identifier is logic. Anything could be the identifier and inside the processor you could define anything to be the outer layer. You could flip data-attr and data-scope just as easily, so I'm not sure where there could ever be an argument that those things represent logic rather than markup.

Either way, I _think_ I have a better understand of potential conflicting views. Thanks for taking the time to explain.

Re: Things every React.js beginner should know

#167
post #7

#10: This guide will be out of date in 3 months.

Good that with Google you can limit your search to a certain time frame. Personally, when I Google stuff about React, I set filter to "Past month" so that most results are quite up to date. I wonder if in the future the project that you start doing in the morning will use outdated libs by the evening ;)

Does this not seem like a problem to anybody else? Wasn't the whole point of React that it was supposed to be simple? And yet things have gotten so complex you're giving advice that anything older than 3 months isn't even worth reading?

Re: Things every React.js beginner should know

#168

I'm not a React or Angular expert, but do you really put HTML inside of your JS code? It just bothers me too much. We spent years in early web days learning that code and templates should be separate, yet here we are putting HTML inside of code, which goes against years of practice. Can anyone share their professional thoughts about this?

It doesn't have to be a debate, everyone can move any one language into the other (JS into HTML, HTML into JS, CSS into JS, etc), as long as they feel that what they write will be something they can reason about later. They should take into account their mindset in 6 months, other people that might be brought on and what their background might be.

The only real issue I see is that if you move HTML into JS, you might make it harder for a pure visual designer to step in and work on HTML/CSS, but outside of that I can't see an issue as long as you keep reasonability of the code in mind. And if you have a good designer, I have a feeling they'll be more than glad to learn how to navigate around Javascript.

Re: Things every React.js beginner should know

#169
post #153

Earlier quoted context omitted.

I explicitly do _not_ state that it applies to React, because there's no domain logic in React components. (Or at least there shouldn't be. It is certainly possible to write a spaghetti component that would do everything.)

> It is certainly possible to write a spaghetti component that would do everything. So...like PHP, then?

[deleted]

Re: Things every React.js beginner should know

#170
post #9

> 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.

Neither 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.ht...

[2] https://facebook.github.io/react/downloads.html#development-...

Post reply on HN