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

Fix undefined function #8

Closed
wants to merge 3 commits into from
Closed

Fix undefined function #8

wants to merge 3 commits into from

Conversation

KimmoHernborg
Copy link

We are using your excellent library in a React Native project, and stumbled onto an issue where some native elements would trigger the throttled functions without any callback. This would trigger a unhandled exception that would crashes the application.

To fix this I simply added the optional chaining operator ?. to the function_ argument, so that if function_ is not set - it will not be called.

@sindresorhus
Copy link
Owner

I think this is something you should handle, not the throttle function. The throttle is documented to accept a non-optional function (in readme and TS). Either guard the call, or pass in a noop function as fallbacK; throttle(foo ?? () => {}).

@KimmoHernborg
Copy link
Author

Alright, thanks for the feedback - I think using a noop function instead as fallback is a good idea. 👍

@KimmoHernborg KimmoHernborg deleted the fix-empty-function branch June 24, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants