I wanted to check if this plugin already does things like this?
Before
const Foo = ({siteId, configId}) => (
<Plot
channelIds={[
`site/${siteId}/simulation/${configId}/inverter/pv_load`,
`site/${siteId}/simulation/${configId}/grid/building_load`,
]}
/>
)
After
const Foo = ({siteId, configId}) => (
<Plot
channelIds={useMemo(() => [
`site/${siteId}/simulation/${configId}/inverter/pv_load`,
`site/${siteId}/simulation/${configId}/grid/building_load`,
], [siteId, configId])}
/>
)
Also children can benefit from memoization too:
Before
const Plot = ({channelIds}) => (
<div>
{channelIds.map(channelId =>
<Trace key={channelId} channelId={channelId} />
)}
</div>
)
After
const Plot = ({channelIds}) => (
<div>
{useMemo(() => channelIds.map(channelId =>
<Trace key={channelId} channelId={channelId} />
), [channelIds])}
</div>
)
I wanted to check if this plugin already does things like this?
Before
After
Also children can benefit from memoization too:
Before
After