React vs Angular 2?

Maximilian

Lifer
Feb 8, 2004
12,604
15
81
Any opinions on this?

Ive googled and it seems React is a smaller thing that needs a bunch of other things to work whereas Angular 2 is this all encompassing does it all out of the box thing but its more restrictive.

Im learning Angular 2 right now and im hoping its the right way to go :\ I made a site a few months back for my final years uni project. I was using JavaScript string concatenation to make the dynamic HTML elements So im learning a good frontend framework so I never have to do that crap again.
 

purbeast0

No Lifer
Sep 13, 2001
53,024
5,905
126
i'm on angular 1.31 or something and i like it a lot now that i get it. it's extremely powerful. it does have a lot of bloat though, and you can run into performance issues when you have a lot of binded objects (i'm talking like 2k) that are all being checked during a digest cycle.

sad thing though is that angular 2.0 is so different that you can't just upgrade to it from a 1.x app. you have to rewrite a buncha shit since they completely changed some fundamental paradigms.

i've never messed with react though. i do like how it works with facebook in the sense that you see "empty spaces" for where things will appear, as soon as the page starts loading ,and it just fills in as data comes back. it makes for a much better UX imo than just having blank stuff or load masks until things load.

i'm actually switching projects in a week or two and will no longer be doing angular professionally but will be moving over to backbone instead. i'm not sure what other technologies are in there though, but it'll be fun to learn a new one.
 

Sgraffite

Member
Jul 4, 2001
107
48
101
Personally, I hate it when pages display little or no content without JavaScript. I gather it's possible to configure at least some of these JavaScript frameworks to display some content without JS, but I don't think it's easy.

https://eev.ee/blog/2016/03/06/maybe-we-could-tone-down-the-javascript/

At least with ASP.NET MVC the server side rendering with ReactJs is just a matter of adding the respective jsx files to the ReactConfig file. It was so easy I thought I was missing something.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Personally, I hate it when pages display little or no content without JavaScript. I gather it's possible to configure at least some of these JavaScript frameworks to display some content without JS, but I don't think it's easy.

https://eev.ee/blog/2016/03/06/maybe-we-could-tone-down-the-javascript/

React supports that out of the box. You can pre-render the final DOM structure on the server, and then when the client side JS loads it just attaches all its hooks to the DOM, doesn't need to do an initial render.

You can still have the issue you describe if your components depend on external data sources though, like a 3rd party API that works on the client side. But as long as you have the data available on your server then with React you can completely avoid the flash of no-content on page load and it's pretty trivial to setup.
 

Cogman

Lifer
Sep 19, 2000
10,283
134
106
So my personal preference is React, here is why.

First off, I think the react model is spot on for what it is supposed to be. Small dedicated components that could be replaced at any time. A "react stack" can be just about anything, there is no rule on what you should bring in. To me, this is a big win of react. Because react is tiny, you can update your application piecemeal. You don't have to upgrade the world to fix one bug, add a new feature, etc. Further, because react forces you down no specific architecture path, it is a lot easier to flexibly decide exactly how your page should be setup and what to depend on.

The react "do one thing well" motto has led to some good innovations (and makes it open to more cool stuff in the future). The original react+flux stack is now commonly react+redux, where redux was written by not facebook. This is the power of react. They chose a good place of where to draw lines on what does what (react is only doing the rendering). Which means that you can decide on which system best fits your data consuming needs. In the case of community adoption, people saw that the redux way was better than the original flux way and jump aboard. But who knows? Maybe redux will go away, time will tell. The important thing here is that your app doesn't care. You can flop out and switch out the data aggregating component on a whim without disrupting the rest of your application.

Compared with Angular, that is the huge win. With angular, you are a slave to the monlyth. The nice thing about Angular is it does almost everything for you. The bad thing about angular is it does almost everything for you. What that means is that you will be fighting, hard, if you ever want to step out of the angular way of doing things. Further, you are bound by what version of angular you pick up. Moving up versions is simply non-trivial. Large swaths of APIs that you or your subcomponents that you pulled in may be deprecated or removed. That is a maintenance nightmare. (Just look at how hard it is for people to go from Angular 1 to Angular 2). The people in the ruby on rails world have experienced similar sorts of heartache with new versions of rails.

Now, there are benefits to the way Angular does things. For starters, because it provides you with everything that means there is less to setup on your side of things. You don't have to hunt down the best date parsing library, there is already one in angular. Further, you don't have to feel shiftless in your design. You do it the angular way, there is no debate on what other way to attack a problem. And finally, while breaking api changes is a problem, the angular team has been pretty good about not doing that much. Further, for smaller apps it isn't really that likely that you will run into issue with it. The benefit here is that with angular, you get a lot of tools in one package that are tested and work together under the same version branch. That isn't so horrible.

However, I think that the larger the app you make, the more untenable the angular approach is. I think that react apps simply have a better long term maintenance story. For react, they just did a really good job at drawing the lines. So what if react decides to makes some big breaking changes? There just isn't enough to the library to really have lots of far reaching effects (So it is much easier to swallow). Further, react just has a better testing story. Getting angular setup for testing requires a good amount of work (and you are bound to the angular testing solution...) and from what I've seen, is often fairly brittle. With react, it is the opposite. React components are (supposed to be) really simple so testing is a breeze. Your components just don't do a lot or have things that they can modify or change. You can do bad things like that, but it is harder with react (and really discouraged).

To me, the biggest feature of react is that it has very few features. It separates concerns and gets out of your way. It very much appears to subscribe to the clean architecture way of doing things, which IMO is the supperior method to do things if you want high maintainability.

That is just my 2 cents. Certainly you can do cool stuff with angular (and people have done a lot of cool stuff with it), the problem I have with it that all angular apps I've seen have some hard to overcome maintenance problems. Often, it seems like intent on these apps are fairly uncleared (controllers end up doing too much, models are ill defined, and the binding and scope is just a hot mess). Angular 2 fixes some of these problems by focusing on a more component based approach, but it remains to be seen if it has done a good job at fixing all of these problems.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
I've been building a React app for the last year. I heavily suggest using React. I pretty much agree with everything Cogman said.

I think Angular is fine for simple interactive pages, but I wouldn't want to build an app with it.
 

purbeast0

No Lifer
Sep 13, 2001
53,024
5,905
126
kind of unrelated, but i talked with an old coworker who is coming on my startup side project, and he was showing/pitching react-native to me this morning and showing me what he has done with it.

i now wish i had written the entire ios app in it (it's about 80% done) because that would mean we would basically have the android version "for free". the part he's coming on board for he's going to be using react-native instead of what the other guy was using with spritekit, and it's going to look great.

he showed me how little work code was written when he just wrote a gesture swiping like tinder has for the cards, and it looked so simple to do.
 

WaitingForNehalem

Platinum Member
Aug 24, 2008
2,497
0
71
Using React for a personal project right now and am loving it. That along with Flux make for a beautiful software architecture.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
For those using React I'm curious to know what language/ecosystem you're coding in.

At my shop we're doing everything with pure coffeescript, no JSX templating at all, inside of a monolithic Rails application.

So in our one application we have various frontend namespaces(www, cms, admin, ops, etc.) along with an API namespace that handles all the JSON requests from the various front ends.

Some of the front ends are built with the entire UI in React as a single page app with client side routing, and others will use Rails server side routing and more traditional Rails rendering with various widgets/components on the page written using React.
 

brianmanahan

Lifer
Sep 2, 2006
24,420
5,852
136
i've been doing Angular 1.x for a couple years now and like it, but still need to give React a try

what i saw of it at some conferences has made me go "meh", though it is usually hard to tell until you actually use it for something real
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
For those using React I'm curious to know what language/ecosystem you're coding in.

At my shop we're doing everything with pure coffeescript, no JSX templating at all, inside of a monolithic Rails application.

So in our one application we have various frontend namespaces(www, cms, admin, ops, etc.) along with an API namespace that handles all the JSON requests from the various front ends.

Some of the front ends are built with the entire UI in React as a single page app with client side routing, and others will use Rails server side routing and more traditional Rails rendering with various widgets/components on the page written using React.

I'm using pure Javascript. We just added Babel to our build so that we can start including ES6.

I use JSX and convert it to JS with a JSX transform in my Webpack build. I can't imagine using React without JSX.

I have a collection of "webapps" and "client apps". A "webapp" is a deployable server instance. If I were Google, GMail and Google Drive would be separate webapps. Each webapp is a collection of "client apps" (i.e. single page apps). In the Gmail example, the inbox and settings menu would be two different clients apps living in the same webapp. The inbox app would include the inbox list view, direct email view, compose view, etc.

I have a single endpoint for each client app (e.g. /inbox) that renders a fairly bare-bones template server-side. This template basically just includes the JS, CSS, and an initial data blob of JSON used to kickstart the React app. I have a collection of API endpoints that can be used across the different client apps.

Each client app has its own compiled JS bundle and CSS bundle. Source code can end up in more than one bundle (if more than one app uses it), but each bundle only includes what that client app needs.
 

Bacon1

Diamond Member
Feb 14, 2016
3,430
1,018
91
Aurelia is another nice framework, made by Rob Eisenberg who created C# framework Caliburn.Micro.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
I'm using pure Javascript. We just added Babel to our build so that we can start including ES6.

I use JSX and convert it to JS with a JSX transform in my Webpack build. I can't imagine using React without JSX.

I have a collection of "webapps" and "client apps". A "webapp" is a deployable server instance. If I were Google, GMail and Google Drive would be separate webapps. Each webapp is a collection of "client apps" (i.e. single page apps). In the Gmail example, the inbox and settings menu would be two different clients apps living in the same webapp. The inbox app would include the inbox list view, direct email view, compose view, etc.

I have a single endpoint for each client app (e.g. /inbox) that renders a fairly bare-bones template server-side. This template basically just includes the JS, CSS, and an initial data blob of JSON used to kickstart the React app. I have a collection of API endpoints that can be used across the different client apps.

Each client app has its own compiled JS bundle and CSS bundle. Source code can end up in more than one bundle (if more than one app uses it), but each bundle only includes what that client app needs.

If I was using Javascript I would agree that not using JSX would be a terrible choice. The conciseness of Coffeescript makes it quite pleasant to build React UIs without JSX though.

I imagine using es6 might be similar.

An example of a simple component that implements Grid rows from the Foundation for sites CSS framework:

Code:
GridRow = React.createClass
  displayName: "UI.GridRow"

  getClasses: ->
    classNames
      "row":true
      "expanded":@props.full_width

  render: ->
    div
      id:@props.id
      className:@getClasses(),
        @props.children

Versus the same component written in JS/X

Code:
GridRow = React.createClass({
  displayName: "UI.GridRow",
  getClasses: function() {
    return classNames({
      "row": true,
      "expanded": this.props.full_width
    });
  },
  render: function() {
    return (
      <div id={this.props.id} className={this.getClasses()}>
        {this.props.children}
      </div>
      );
  }
});
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
I think I still prefer the JSX because it more resembles the HTML that it ultimately generates.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
I think I still prefer the JSX because it more resembles the HTML that it ultimately generates.

And that's precisely why we don't use it. I haven't written a closing HTML tag in years now between using HAML and React.
 

purbeast0

No Lifer
Sep 13, 2001
53,024
5,905
126
the syntax for react looks a bit funky there, but it's only funky because i have never done it before. i like it over having to do html though. i could definitely get used to that.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
the syntax for react looks a bit funky there, but it's only funky because i have never done it before. i like it over having to do html though. i could definitely get used to that.

Well that example is a bit contrived, you're likely to only have a handful of components that are like this in an entire application, it doesn't really do anything. It's missing out on like 95% of the features of the React API. Also it's using a global helper method call classNames that takes an object with truthy values and will join all the keys with value true into a space separated string. It's used for building strings of classnames for the HTML tags.

React is all about managing a state object in the higher-level components and passing down various slices of the state as properties to components that you are using to render the HTML. The basics of rendering are that if a components properties or state has changed then the virtual DOM is re-rendered and reconciled against the actual DOM.

React provides a very well defined render and state management lifecycle. Any given component is basically a set of lifecycle callbacks + helper methods. How dynamic and interactive the component is will mostly dictate how many of the lifecycle callbacks you will use.

Generally it is a lot easier to create small components that do one thing really well then it is to try and create one big component that renders the entire page in one render() definition.
 
Last edited:
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |