-
Notifications
You must be signed in to change notification settings - Fork 48
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
[Feature]: exporting useTimout? #1094
Comments
@manudeli, can you tell me more about what "suspensive interfaces" mean? |
I changed description for this repository like below after #1072 AS IS"Packages to use React Suspense easily" TO BE"Manage asynchronous operations, timing, error handling, detecting intersection of elements, and caching easily" So I thought useTimeout could be "Suspensive interfaces(timing)" @bigsaigon333 But I want to check whether this vision is good for you too. |
What a nice discussion! I read #1072 thoroughly and agree with this description 100%.
However, I wanted to add some words after I believe that we can provide not only any hook related to asynchronous operations but also declarative React components corresponding to those hooks. The relationship between
|
I added it now! thanks for your feedback! |
I didn't think about |
Well, I just thought using
This below is just pseudo code. import { use } from 'react';
function createTimeoutPromise(duration) {
return new Promise(resolve => setTimeout(resolve, duration));
}
function Timeout({ duration, children, fallback }) {
use(createTimeoutPromise(duration)); // Suspend until promise resolves
return <>{children}</>; // Render children after the timeout
} I'm trying to understand where a component would be particularly useful, but I haven't come across a specific example that demonstrates its necessity. 😭 What do you think, @manudeli? |
Sadly, in my opinion, It's the most important thing that finding example use cases!
Good idea, but I think this will make circular suspending on render.
I fixed it as below. but it have problem that we cannot control timing promise start time import { use } from 'react';
function createTimeoutPromise(duration) {
return new Promise(resolve => setTimeout(resolve, duration));
}
const promiseTimeout = createTimeoutPromise(duration) // single source of promise should be guaranteed to suspend only one time
function Timeout({ duration, children, fallback }) {
use(promiseTimeout);
return <>{children}</>;
} So we can make it as cache on mount using @tanstack/react-query or @suspensive/cache to cache promise to suspend only one time on mount import { useCache } from '@suspensive/cache';
function createTimeoutPromise(duration) {
return new Promise(resolve => setTimeout(resolve, duration));
}
function TimeoutOnlyOneTime({ duration, children, fallback }) {
useCache({
cacheKey: ["cached"],
cacheFn: () => createTimeoutPromise(duration)
}) // only one time make promise on mount of TimeoutOnlyOneTime
return <>{children}</>; // Render children after the timeout
} |
Package Scope
@suspensive/react
Description
useTimeout could suspensive interfaces?
Possible Solution
No response
etc.
No response
The text was updated successfully, but these errors were encountered: