pure react components 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
// index.js
import { Router } from 'react-router-dom'
import history from './history'
import App from './App'
ReactDOM.render((
), holder)
Example 3: pure components
import { useHistory } from "react-router-dom";
function HomeButton() {
const history = useHistory();
function handleClick() {
history.push("/home");
}
return (
);
}