Skip to content

[FEATURE] usePolling #224

Open
Open
@gaki2

Description

@gaki2

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.

When implementing polling functionality, it's challenging to handle various edge cases declaratively, and it often requires writing extensive boilerplate code to manage all possible scenarios properly.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Interface Example

type PollingOptions<R> = {
  successWhen: (result: R) => boolean;
  cancelWhen: (result: R) => boolean;
  interval: number;
  intervalExponent?: number;
  endTime?: number;
};

const { data, loading, error } = usePolling(pollingCallback, pollingOptions);

When using this type of usePolling hook, a key advantage is that it allows you to manage asynchronous polling requests declaratively without boilerplate code. This creates a cleaner, more maintainable way to handle periodic API calls while waiting for specific conditions to be met.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

While this could be handled using React Query's refetch functionality, React Query has the drawback of being complex and heavyweight in specific use case.

Additional context
Add any other context or screenshots about the feature request here.

core: https://gist.github.com/gaki2/fee252205f1a8feb6bd5331608ccd7f9

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions