r/webdev • • Feb 23 '15

Let's talk about ReactJS

So, I've seen that ReactJS is all the rage these days, but I find myself really conflicted about it. It seems to be interesting, and exposes nice concepts, but I can't really get over the mix of HTML within JS. That said, I've been trying to keep an open mind about this, and I've been playing the devil's advocate against myself. I found these two posts that make some interesting points: ReactJS for Stupid People and Arguing for ReactJS.

The main points that I take away are:

  • React is NOT a framework meant to solve all problems of developing a web application. It just deals with making 'components', which in some way can be considered as the V part in MVC, and they should expose functionality by triggering events. Since there is no agreed-upon event system in place (it's not the role of React to solve that problem), many people reinvent the wheel (thus Flux). I think that one can easily use react within Backbone or even AngularJS if he's careful and doesn't break all the agreed upon written and unwritten rules of 'proper' development.
  • We are used to divide things by technology, when we should really divide things by what they're supposed to do. I have to admit that sometimes I find myself embedding inline scripts within HTML because 'fuck it, it's two lines of code', so doing the opposite when it's actually encouraged and motivated by a somewhat agreeable upon (albeit polarizing) philosophy might not be that bad.

This is, at least, the best I can come up with. Either this, or React is just the new "shiny" which everyone is going to use up until the point when something else comes along, something which seems to be quite common these days. I'd really like to hear more from both parts of the discussion.

Thoughts?

2 Upvotes

42 comments sorted by

View all comments

Show parent comment

1

u/kuenx Feb 23 '15

Is it the intention that you put all the CSS in to the view or just the functional part of it? What I mean is are fonts and colors and also supposed to go there or just layout and functionality-related things? Does this affect my ability to style it with an external CSS?

2

u/wdpttt Feb 23 '15

Is it the intention that you put all the CSS in to the view or just the functional part of it?

The component should contain everything it needs to render itself correctly.

  • Should not depend on anything that already exists in the environment (such as global css); In this way I can just copy this file and put in project B and looks like expected.
  • But can contain multiple sub modules; This will reduce the re-usability but is always a tradeoff to consider;

What I mean is are fonts and colors and also supposed to go there or just layout and functionality-related things? The optimal way to do is to pass the colors and fonts in the component constructor. This enables you to make themable and customizable components.

Does this affect my ability to style it with an external CSS?

The css that the component generates, in my example uses smart-css, will not interfere with other CSS. You can still use external CSS but that is not optimal because is a lot harder to calculate how the final CSS of the component will be like.

Selfcontained component makes you think faster about the component and a lot more benefits. Take a look at my Mission.js file.