Skip to content

Instantly share code, notes, and snippets.

@netshade
Last active August 29, 2015 14:14
Show Gist options
  • Save netshade/60ca809543e1ddb6cd70 to your computer and use it in GitHub Desktop.
Save netshade/60ca809543e1ddb6cd70 to your computer and use it in GitHub Desktop.
What has been good about React

Here's what's been good so far about React:

As UI components get more complex in JS, there's this inevitable attempt to push state into the actual HTML. Check a DOM node for an attribute, then act off of it. As that pattern begins to increase, more and more code starts deferring a UI's logical state out to the physical state of the DOM. This rarely seems to be what is intended.

What is intended is that the application /knows/ what the right state is, and the HTML is a side effect of reflecting that state. React encourages good practice in making the HTML a side effect of a React component's props, and efficiently handles the tree transitions. Without getting into the mechanics of how I personally structure React components, the set of guarantees you get when pushing as much "immutable properties, reproducible layout" into your components lets you have these really trustworthy, easy to develop UI pieces that don't inherit the bad parts of UI programming where you call out to application and implementation properties at the same time.

Stuff like (admittedly a contrived bad example):

if(domNode.style.display == 'none'){ // developer presumes that domNode's layout has a logical meaning
  if(myUser.mustLogin){
    domNode.style.display = '';
  }
}

goes away, because you never have domNode in the first place. You are only ever concerned with what the HTML should like based on your current application state, which removes the conditional behavior, which makes the end result far easier to test and guarantee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment