Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Hook Proposal: useTimeoutControlledFn — a manual version of useTimeoutFn

Đang mở
#2,645 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Start by locating the existing useTimeoutFn implementation and its tests, since this proposal defines a manual variant of that hook. Confirm the start, cancel, reset, and readiness behavior from the issue, then add tests and documentation showing that no timeout starts on mount and that the requested API works.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

useTimeoutFn, starts the timeout automatically on mount. In our case, we needed something similar but fully manual which is a timeout only starts when we explicitly trigger it (e.g., after an API success).

Why this might be useful
  • No automatic timeout on mount
  • Full control: start(), cancel(), reset()
  • Ability to reuse the last delay (reset)
  • Useful in callbacks, controlled UI flows, etc.
API
const [isReady, cancel, start, reset] = useTimeoutControlledFn(fn, defaultMs?: number);
  • isReady() → returns true | false | null
  • cancel() → cancels the current timeout
  • start(delay?) → starts a new timeout
  • reset() → reuses last delay
Example
const [isReady, cancel, start, reset] = useTimeoutControlledFn(() => {
  console.log('Executed after delay!');
}, 1500);

// Manually start after a successful API call
const onApiSuccess = () => start();

If this sounds useful, I’m happy to prepare a full PR with tests and docs. Just wanted to get your feedback first

Ngôn ngữ chính
TypeScript
Star
44k
Fork
3.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của streamich/react-use

Tất cả issue của streamich/react-use

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.