Skip to content

Instantly share code, notes, and snippets.

@will-wow
Created July 23, 2019 00:11
Show Gist options
  • Save will-wow/389cda0b3fd48fecf470a5f06fa61ee6 to your computer and use it in GitHub Desktop.
Save will-wow/389cda0b3fd48fecf470a5f06fa61ee6 to your computer and use it in GitHub Desktop.
Sample code for a blog post about Optimizing Performance in React 18.6
import React from "react";
const BigGrid = ({ number }) => {
...
};
export default React.memo(BigGrid);
const BigGrid = ({ numbers }) => {
...
};
<BigGrid numbers={[firstNumber, secondNumber]} />
const numbers = React.useMemo(() => [firstNumber, secondNumber], [firstNumber, secondNumber]);
<BigGrid numbers={numbers} />
const [x, setX] = useState(1);
const logX = useCallback(() => console.log(x), [x]);
return <SomeComponent onClick={logX} />
const numbers = React.useMemo(() => [firstNumber, secondNumber], [firstNumber, secondNumber]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment