Skip to content
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

feat: new hook useThrottleCallback #118

Merged
merged 1 commit into from
Jun 15, 2021
Merged

feat: new hook useThrottleCallback #118

merged 1 commit into from
Jun 15, 2021

Conversation

xobotyi
Copy link
Contributor

@xobotyi xobotyi commented Jun 12, 2021

What new hook does?

Makes passed function throttled, otherwise acts like useCallback.

Checklist

  • Have you read contribution guideline?
  • Does the code have comments in hard-to-understand areas?
  • Is there an existing issue for this PR?
  • Have the files been linted and formatted?
  • Have the docs been updated?
  • Have the tests been added to cover new hook?
  • Have you run the tests locally to confirm they pass?

@xobotyi xobotyi added the 🎂 new hook New hook added label Jun 12, 2021
@xobotyi xobotyi requested a review from JoeDuncko June 12, 2021 21:07
@codecov
Copy link

codecov bot commented Jun 12, 2021

Codecov Report

Merging #118 (8f1cc0d) into master (f51ae8e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #118   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           31        32    +1     
  Lines          498       524   +26     
  Branches        91        96    +5     
=========================================
+ Hits           498       524   +26     
Impacted Files Coverage Δ
src/useCookieValue/useCookieValue.ts 100.00% <ø> (ø)
src/useStorageValue/useStorageValue.ts 100.00% <ø> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/useThrottleCallback/useThrottleCallback.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f51ae8e...8f1cc0d. Read the comment docs.

Copy link
Contributor

@JoeDuncko JoeDuncko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The demo seems to be broken, so I think the throttle implementation might be wrong or I might be misunderstanding using throttle in this case.

It seems that this throttle callback drops the final run on the floor. See the example below - there is more text in the box than the displayed value, even through 500ms has passed.

image

src/useThrottleCallback/__docs__/example.stories.tsx Outdated Show resolved Hide resolved
src/useThrottleCallback/__docs__/story.mdx Outdated Show resolved Hide resolved
src/useThrottleCallback/__docs__/story.mdx Outdated Show resolved Hide resolved
@xobotyi
Copy link
Contributor Author

xobotyi commented Jun 14, 2021

Ah🤔 interesting, I'll watch other implementations, but this seems to be proper behavior, according to what is throttling.

@JoeDuncko
Copy link
Contributor

Just checked, react-use's implementation doesn't drop the last value on the floor, see https://streamich.github.io/react-use/?path=/story/side-effects-usethrottle--demo .

Copy link
Contributor

@JoeDuncko JoeDuncko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better!

@xobotyi xobotyi merged commit afec60b into master Jun 15, 2021
@xobotyi xobotyi deleted the useThrottleCallback branch June 15, 2021 13:32
github-actions bot pushed a commit that referenced this pull request Jun 15, 2021
# [2.2.0](v2.1.0...v2.2.0) (2021-06-15)

### Features

* new hook useThrottleCallback ([#118](#118)) ([afec60b](afec60b))
@xobotyi
Copy link
Contributor Author

xobotyi commented Jun 15, 2021

🎉 This PR is included in version 2.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants