Lesson Learnt: Isolate Components Behavior in ReactJS

Reading Time: 4 minutes

hangmanA few weeks ago I complained that calling asynchronous operations inside Reacts lifecycle method componentWillMount like AJAX may have collateral effects. In my case, the application hangs and stuck inside an infinite rendering loop. I discovered that my first attempt to solve the problem was by no way the solution, although I thought it was. The real cause was an unfortunate composition of components. The scenario was the following:

Continue reading

Do not make asynchronous calls within ReactJS's componentWillMount method

Reading Time: 1 minutes

It's a really bad idea to execute asynchronous calls, i.e. AJAX, within the componentWillMount() method. Well, on the ReactJS site, they simply say not to do, but do not mention why. I know now!
I experienced an infinite loop of componentWillMount while making an AJAX call inside componentWillMount. Shifting the code from componentWillMount to componentDidMount resolved my problem instantly; but to get there I lost about three hours of my life.

UPDATE: This was not the real problem. See more here!