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

Create an escape hatch #3

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

Create an escape hatch #3

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

Comments

@yuchi
Copy link
Owner

yuchi commented Nov 29, 2018

Sometimes a single reference should be kept out of the inputs array, we could allow the user to specify it. A proposed syntax is:

import { stale, useAutoMemo } from 'hooks.macro';
import { useRandomValue } from 'minister-of-silly-hooks';

function MyComponent({ prop }) {
  const rnd = useRandomValue();
  const value = useAutoMemo(prop * stale(rnd));
}
@yuchi yuchi added enhancement New feature or request help wanted Extra attention is needed labels Nov 29, 2018
@neoncube2
Copy link

IMHO, it should also be possible to specify multiple inputs that should be kept out of the input array 🙂

Not sure what the syntax for that would be like. The first thing that comes to mind is to use the same syntax that memo() uses, but have the array specify what arguments to exclude from memoization.

i.e.

function MyComponent({ prop }) {
  const rnd = useRandomValue();
  const value = useAutoMemo(prop, [rnd]);
}

😄

@yuchi
Copy link
Owner Author

yuchi commented Jan 26, 2021

This is both a fantastic and terrible idea. It does makes sense but it makes reading the syntax a nightmare.

It could also be useAutoMemo(……, { exclude: [ …… ] }) which makes it a little bit more explicit and opens the road to other configuration in the future

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

2 participants