pure react component code example
Example 1: react with pure components
Simple example of react pure component
import React from 'react';
class PercentageStat extends React.PureComponent {
render() {
const { label, score = 0, total = Math.max(1, score) } = this.props;
return (
{ label }
{ Math.round(score / total * 100) }%
)
}
}
Example 2: pure components
// history.js
import { createBrowserHistory } from 'history'
export default createBrowserHistory({
/* pass a configuration object here if needed */
})
Example 3: pure components
// some-other-file.js
import history from './history'
history.push('/go-here')