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(useEventCallback): allow optional callback #550

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

Newbie012
Copy link
Contributor

Updated the useEventCallback hook to accept an optional callback function. This improves developer experience by allowing more flexibility in the use of the hook.

This is quite useful when you want to memoize a callback prop that can be optional. For instance:

type Props<T> = {
  onChange?: (value T | undefined) => void;
}

function Comp({ onChange }: Props) {
  const onChangeRef = useEventCallback(onChange); 

  return <ExpensiveCompImpl onChange={onChangeRef} />
}

Updated the useEventCallback hook to accept an optional callback function. This improves developer experience by allowing more flexibility in the use of the hook.
Copy link

changeset-bot bot commented Mar 21, 2024

🦋 Changeset detected

Latest commit: e00576a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
usehooks-ts Patch
www Patch

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

@juliencrn
Copy link
Owner

Hi @Newbie012, well done, thank you 👍

@juliencrn
Copy link
Owner

@all-contributors please add @Newbie012 for code

Copy link
Contributor

@juliencrn

I've put up a pull request to add @Newbie012! 🎉

@juliencrn juliencrn merged commit 09341a3 into juliencrn:master Mar 21, 2024
1 of 2 checks passed
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