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

Custom caching function #16

Open
Splact opened this issue Oct 22, 2020 · 1 comment
Open

Custom caching function #16

Splact opened this issue Oct 22, 2020 · 1 comment

Comments

@Splact
Copy link

Splact commented Oct 22, 2020

I'm working with threejs and here using usePromise to load an external model it works the first time, but not on successive use of the loader on the same resource. Would be nice to have the ability to assign a function that defines the copy logic, with threejs this can be done with mesh.clone(); for example.

This is how the usePromise could work.

  const data = usePromise(
    fetchJson, [
      'https://pokeapi.co/api/v2/pokemon/ditto/',
      { method: 'GET' },
    ],
    {
      // options object instead of single argument for lifespan
      lifespan: 1000,
      onCache: (originalResponse) => myCustomCloneFunction(originalResponse)
    }
);
@msereniti
Copy link

You can use fork of this package that solves this issues and also allows you to provide a custom cache comparer. Suppose custom comparer may be much better solution that custom clone function as far as this package doesn't clone promise result

react-use-await

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants