Skip to content

Error/warn on known non-invariants #7

@yuchi

Description

@yuchi

In the following example the current implementation outputs very useless code for useAutoMemo and useAutoCallback, and potentially un-performant code for effects:

function MyComponent({ prop }) {
  const config = { a: prop };
  return useAutoMemo(JSON.stringify(config));
}

The obvious reason is that config will always be different from the previous render. To “solve” it we need to wrap the object literal in useAutoMemo:

function MyComponent({ prop }) {
  const config = useAutoMemo({ a: prop });
  return useAutoMemo(JSON.stringify(config));
}

The macros should at least warn about this borderline situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions