Tuesday, June 23, 2015

Why people like React?


I recently used React in my recent project. I am definitely a newbie. I read articles from internet. A lot of people seems excited about React. I just don't know why...

Here are some things I don't like React.

  • It needs compile the jsx to js. The code you wrote is not the code running in browser.
  • The code is not neat. If you compare the compiled js with the jsx. They are similar but the compiled js is more verbose. So I guess using jsx is to make code short and easy to read. But is the jsx really neat? To create a simple div, I need write
  • The code generated by runtime compiler does not equal to the compiled js. One example is that when using runitme compiler, in an external js file, I cannot get the reference of any React component. And the React components created in one jsx cannot refer to another React component created in another jsx.
    var ComponentA = React.createClass({render: function(){     return <div>abcdefg...</div>;}});



  • Another question mark is that the html is mixed in javascript method. Good? Bad? At least it is not my favorite.
  • React brings in new concept to learn. like state and property, like the lifecycle, componentDidMount, componentWillMount, componentWillReceiveProps... Learning curve is not that short. Here is one article talking about state and property: http://github.com/uberVU/react-guide/blob/master/props-vs-state.md
  • Dom cannot be changed. I tried to use JQuery Dialog, but I always got error. The reason is that JQuery change the DOM but React does not allow that. There are solutions online, but React makes the work complicated. 
    http://sterling.ghost.io/working-with-jqueryui-and-reactjs-components/
    http://blog.arkency.com/2014/10/you-can-move-react-root-component-around/
    https://groups.google.com/forum/#!msg/reactjs/mHfBGI3Qwz4/6s-eHGEpccwJ
  • Initial State does not support complicated object.
    https://jsfiddle.net/hairinwind/6t7Lcz8s/1/
    If you comment js line 5 and uncomment line 4, you will see the error."Cannot read property 'name' of undefined"
  • More...


    As I said, I was a newbie. For some problems listed above, like #2, there might be a way to solve it. I did google it on internet but I did not find an easy way. 

  • Here is the cheatsheet for react.js http://ricostacruz.com/cheatsheets/react.html

    No comments:

    Post a Comment