Skip to content

Instantly share code, notes, and snippets.

const Child = React.memo(
({ isAboveFive, children }) => {
console.log("child renders");
return (
<>
<h2>Child: {!isAboveFive ? "<= 5" : "> 5"}</h2>
{children}
</>
);
},
const App = () => {
const [counter, setCounter] = useState(0);
const [aboveFive, setAboveFive] = useState(false);
const increment = () => {
setCounter(n => n + 1);
};
useEffect(() => {
if (counter > 5) {
const App = () => {
const [counter, setCounter] = useState(0);
const [aboveFive, setAboveFive] = useState(false);
const increment = useCallback(() => {
setCounter(n => n + 1);
}, []);
useEffect(() => {
if (counter > 5) {