React
class SomeComponent extends React.Component {
constructor() {
super(...arguments)
this.state = {
some: 'value'
}
}
componentWillMount
someCallback(event) {
console.log(event.target.innerHTML)
}
render() {
const { data, component: HOComponent } = this.props
return (
<div onClick={this.someCallback}>
{ data }
<HOComponent />
// <SomeOtherComponent /> так тоже сработает
<HOComponent>
{ 111 }
</HOComponent>
</div>
)
}
}
SomeComponent.propTypes = {
data: React.PropTypes.string,
component: React.PropTypes.func
}
class SomeOtherComponent extends React.Component {
render() {
const { children } = this.props
return <div>{ children }</div>
}
}
ReactDOM.render(
<SomeComponent
data={'Hello World!'}
component={SomeOtherComponent}
/>,
document.getElementByid('container')
)
Life cycle methods
- componentWillMount
- componentDidMount
- componentWillReceiveProps
- shouldComponentUpdate
- componentWillUpdate
- componentDidUpdate
- componentWillUnmount