-
Notifications
You must be signed in to change notification settings - Fork 94
Allow possibility to resolve data synchronously #155
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
Comments
How would values be added to the cache? With In a future version, I'm considering renaming |
I would leave it up to the user of the library. I, for myself, created a I like this library because it doesn't try to do everything and I think that's the way to go in the future aswell. It is quite simple to create your own hooks that utilize the |
The |
I think direct cache support depends on where we're going with Suspense support. Suspense was designed to be used with a cache. It works without one, but it's foregoes the render optimization that you can get by synchronously resolving the data. Personally I don't care too much about some additional renders, but some people tend to make a big deal about it. |
I think that saving a single render (when using cache with Suspense) could be considered a nice to have feature. That being said, perhaps caching shouldn't be integrated into the library but it should still be relatively easy to implement using |
Uh oh!
There was an error while loading. Please reload this page.
Would it be possible to somehow provide
Async
anduseAsync
a way to resolve data synchronously? This would allow the use of any synchronous caching solution and eliminate rerenders caused by status updates. At the current state of the library, I have only come up with a solution that memoizes thepromiseFn
function, however it is still asynchronous.This might not be the best API, but for the sake of an example case:
Optional
cacheFn
argument would introduce a way to resolve data synchronously and it should be the primary way to resolve the data (secondary would be to use the good oldpromiseFn
). This way no additional renders are required in case thefn
function can resolve the data (it returns something else thanundefined
).cacheFn
function would receive the same arguments as thepromiseFn
function.Because this solution is quite flexible, we could easily disable cache by conditionally providing the
cacheFn
function:If this can be done another way, without introducing a new argument I would gladly hear about it.
Edit: Renamed
fn
tocacheFn
, because it describes the usage better.The text was updated successfully, but these errors were encountered: