var PureRenderMixin = require('react-addons-pure-render-mixin');
var Button = React.createClass({
mixins: [PureRenderMixin],
componentDidMount: () {
...
},
render: () {
...
}
});
class DataProvider extends React.Component {
render() {
const someData = ...
return this.props.render(someData)
}
}
<DataProvider render={data => (
<h1>Hello {data.target}</h1>
)}/>
Using state inside function components
import React, { useState } from 'react';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
Acting on component lifecycle
import React, { useState, useEffect } from 'react';
function Example() {
const [count, setCount] = useState(0);
// Similar to componentDidMount and componentDidUpdate:
useEffect(() => {
// initialize jquery dropdown
});
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
useReducer
useContext
custom hooks - define your own hooks