Skip to content

Instantly share code, notes, and snippets.

View harishtella's full-sized avatar

Harish Tella harishtella

View GitHub Profile
@slikts
slikts / react-memo-children.md
Last active May 17, 2024 16:39
Why using the `children` prop makes `React.memo()` not work

nelabs.dev

Why using the children prop makes React.memo() not work

I've recently ran into a pitfall of [React.memo()][memo] that seems generally overlooked; skimming over the top results in Google just finds it mentioned in passing in a [React issue][regit], but not in the [FAQ] or API [overview][react-api], and not in the articles that set out to explain React.memo() (at least the ones I looked at). The issue is specifically that nesting children defeats memoization, unless the children are just plain text. To give a simplified code example:

const Memoized = React.memo(({ children }) => (<div>{children}</div>));
// Won't ever re-render
<Memoized>bar</Memoized>
// Will re-render every time; the memoization does nothing
@harishtella
harishtella / box-plot.vg.json
Last active October 11, 2019 22:49
Vega-lite: comparing box-plot and strip-plot
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"height": {"step": 30},
"width": 300,
"description": "Shows the relationship between horsepower and the numbver of cylinders using tick marks.",
"data": {"url": "data/cars.json"},
"mark": {
"type": "boxplot",
"extent": "min-max"
},