Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error/warn on known non-invariants #7

Open
yuchi opened this issue Nov 29, 2018 · 0 comments
Open

Error/warn on known non-invariants #7

yuchi opened this issue Nov 29, 2018 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@yuchi
Copy link
Owner

yuchi commented Nov 29, 2018

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.

@yuchi yuchi added enhancement New feature or request help wanted Extra attention is needed labels Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant