Repository navigation
refactor(useInterval, useTimeout): take a single options object - #530
Conversation
🦋 Changeset detectedLatest commit: d4bae72 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Size Change: +24 B (+0.02%) Total Size: 116 kB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v1-base #530 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 71 71
Lines 2287 2287
Branches 735 732 -3
=========================================
Hits 2287 2287 🚀 New features to boost your workflow:
|
// Before
useInterval(tick, { delay: 1000, immediate: true });
useDebouncedCallback({ onChange: setQuery, timeThreshold: 300, leading: true });
useThrottledCallback({ onChange: setTop, timeThreshold: 200, edges: ['leading'] });
// After
useInterval(tick, 1000, { immediate: true });
useDebouncedCallback(setQuery, 300, { leading: true });
useThrottledCallback(setTop, 200, { edges: ['leading'] });With positional arguments, 300 and 200 lose their names at the call site. What do you think? 🤔 🤔 🤔 |
c36cf6e to
41bf0a7
Compare
|
@hyesungoh Totally agree! Seeing a bare
useInterval({ onTick: poll, delayMs: 1000, immediate: true });
useTimeout({ onTimeout: close, delayMs: 3000 });
|
Overview
useIntervalanduseTimeoutnow take a single options object that holds the callback and the delay. Closes #527.This reverses the first draft, which moved required values into positional arguments. As review pointed out, a call like
useDebouncedCallback(setQuery, 300)hides what300means at the call site.useDebouncedCallbackanduseThrottledCallbackalready take an object, so this PR leaves them as they are.onprefix used byonClickandonChange:onTickandonTimeout.delayMs, following Name time options with a millisecond suffix #536. This also covers theuseTimeoutitem in Name time options with a millisecond suffix #536.useIntervalno longer accepts a bare number as its delay.required: falseflags in the KoreanuseIntervaldoc, and an untranslated example comment in the zh-HansuseTimeoutdoc.yarn test,yarn test:coverage,yarn test:compiled,yarn test:docsandyarn test:skillpass.Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?