About many things

Things that you should know about React

I just started using Facebook’s React library and want to share the most important things that one should always keep in mind when using library.

I will list below some things starting from the most important ones.

Flux

Facebook suggests its own architecture for building UI called Flux and as they claim this architecture is better scalable and testable compared to MVC architecture.

I suggest you watch the video below about it:

My points

Few important things that you always should keep in mind are:

  • render() method is always called when state of component is changed

  • render() method does not completely re-render DOM node every time, instead it uses virtual DOM mechanism to detect changes and then apply only them

  • You should keep render() as flat as it is possible and should never use setState() there as it may cause infinite loops

  • You can access sub components using ref attribute

  • You definitely may want to add JSX sugar to your react app, but remember that it is not part of react library itself

Quick start project

You might want to check quick start project that I published here.

Installation

Via git (or downloaded tarball):

$ git clone git://github.com/gevorg/react-quick-start.git

Running

$ cd react-quick-start
$ npm install
$ npm start

> node app.js

Listening on 5000
...
#javascript #react #flux