Sitemap
Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Member-only story

Optimizing Performance Using React.memo

--

Press enter or click to view image in full size

React.memo is a higher-order component in the React library. Higher-order components take another component as an argument and return a modified version of the component.

In practice, React.memo memoizes a component such that it does not rerender if its props do not change. When used on a component, it makes a shallow comparison of the props it received whenever its parent rerenders. Let’s take a look at a demo I created.

This repo of this demo can be found here:

There are two components here:

App.jsx

function App() {
const [count, setCount] = useState(0)
const [childColor, setChildColor] = useState('#fffaaa')
const generateRandomColor = () => {
setChildColor( '#' + Math.floor(Math.random()*16777215).toString(16));
}
return (
<div className="App">
<div…

--

--

Jonathan Brierre
Jonathan Brierre

Written by Jonathan Brierre

I am a published author as well as a software engineer. I like thinking, thinking about thinking, and thinking about how I think about the things I think about