Skip to content

Commit

Permalink
Make useOnMountEffect accept functions with void return types (#2089)
Browse files Browse the repository at this point in the history
## Summary:
Previously, `useOnMountEffect` accepted functions that either return a cleanup function or explicitly return undefined. This means that functions with no return value (e.g. `() => {}`) result in errors, even though they're accepted by `useEffect`. This PR updates the argument type so that it accepts functions with void returns. Minor version bump because the API changed, but it is non-breaking.

## Test plan:
N/A

Author: timmcca-be

Reviewers: kevinbarabash

Required Reviewers:

Approved By: kevinbarabash

Checks: ✅ codecov/project, ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 16.x), ✅ Test (ubuntu-latest, 16.x, 2/2), ✅ Check build sizes (ubuntu-latest, 16.x), ✅ Lint (ubuntu-latest, 16.x), ✅ Test (ubuntu-latest, 16.x, 1/2), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 16.x), ✅ Publish npm snapshot (ubuntu-latest, 16.x), ⏭  Chromatic - Skip on Release PR (changesets), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 16.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 16.x), ⏭  dependabot, ✅ gerald

Pull Request URL: #2089
  • Loading branch information
timmcca-be authored Oct 19, 2023
1 parent f620da3 commit 7055ca9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-kings-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-blocks-core": minor
---

Make useOnMountEffect accept functions with void return types
4 changes: 1 addition & 3 deletions packages/wonder-blocks-core/src/hooks/use-on-mount-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import * as React from "react";
*
* If you only need to do something on mount, don't return a cleanup function from `callback`.
*/
export const useOnMountEffect = (
callback: () => undefined | (() => void),
): void => {
export const useOnMountEffect = (callback: () => void | (() => void)): void => {
// eslint-disable-next-line react-hooks/exhaustive-deps
React.useEffect(callback, []);
};

0 comments on commit 7055ca9

Please sign in to comment.