Немного обновить с помощью классов ES6
вместо React.createClass
import React, { Component } from 'react';
class SomeComponent extends Component {
constructor(props) {
super(props);
// this code might be called when there is no element avaliable in `document` yet (eg. initial render)
}
componentDidMount() {
// this code will be always called when component is mounted in browser DOM ('after render')
}
render() {
return (
Some Content
);
}
}
Также - проверить методы жизненного цикла компонентов React: https://facebook.github.io/react /docs/react-component.html#the-component-lifecycle
Каждый компонент имеет множество методов, подобных componentDidMount
, например
componentWillUnmount()
- компонент будет удален из браузера DOM