feat(useTimeoutEffect): Implement useTimeoutEffect
What new hook does?
Functions like setTimeout, except in hook form. Returns a method to cancel the timeout, and a method to restart the timeout. It does not cause any rerenders.
Checklist
- [x] Have you read contribution guideline?
- [x] Does the code have comments in hard-to-understand areas?
- [x] Is there an existing issue for this PR?
- https://github.com/react-hookz/web/issues/33
- [x] Have the files been linted and formatted?
- [x] Have the docs been updated?
- [x] Have the tests been added to cover new hook?
- [x] Have you run the tests locally to confirm they pass?
Codecov Report
Merging #886 (b119bb7) into master (3762f78) will not change coverage. The diff coverage is
100.00%.
@@ Coverage Diff @@
## master #886 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 58 59 +1
Lines 1003 1023 +20
Branches 181 183 +2
=========================================
+ Hits 1003 1023 +20
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/index.ts | 100.00% <100.00%> (ø) |
|
| src/useTimeoutEffect/useTimeoutEffect.ts | 100.00% <100.00%> (ø) |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
I was hesitant about including the cancel and reset return values. It is possible to get the same functionality by changing the timeout to undefined in order to cancel the function, and a reset is possible by either changing the timeout, or setting it to undefined and then back to the same value if necessary.
The downside of this is that these methods then require rerenders, which the original method didn't need, and the current cancel and reset methods also don't need in order for them to work correctly.
:tada: This PR is included in version 15.1.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: