Skip to content

Instantly share code, notes, and snippets.

React.js State Explained

var React = require('react');
var $ = require('jquery');
/********************************************************
This code is to explain state mutation in React and demo
why immutable.js is a better approach
**********************************************************/
var Test = React.createClass({

The case that you have to use Immutable.js in React

In React, there are scenarios that you have to use Immutable.js if you want to use shouldComponentUpdate to improve performance.

For example if your state is an object or array in a flux data store

  this.var1 = {a:1, b:2};
  this var2 = [1,2,3];

Closure and Const/Let

_createClass(Contact, [{
	    key: 'render',
	    value: function render() {
	      var self = this;
	      var controls = [];
	
	      var _loop = function _loop() {
  • npm install express

  • npm install -g node-inspector

  • npm install -g devtool

  • devtool app.js --watch

  • npm install mongodb