Skip to content

Memoized values with empty inputs array are known to be static #12

@yuchi

Description

@yuchi

In the following example the value of values should never change, and we should be able to treat it as static:

const values = React.useMemo(() => new Array(12), []);

I say “should” because the official React documentation states:

You may rely on useMemo as a performance optimization, not as a semantic guarantee.
In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without useMemo — and then add it to optimize performance.

We will skip this optimization since we cannot guarantee the semantic correctness in the long run.

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