Skip to content

[Feature request?] Memoizing object and array literals passed to React properties, child array mapping #1

@jedwards1211

Description

@jedwards1211

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>
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions