usehooks-ts
usehooks-ts copied to clipboard
Feature: Add useEffectTill
PR Description
Summary
This PR introduces a custom React hook, useEffectTill, designed to run an effect only until it is marked as done, handling cleanup afterward. The hook enhances the standard useEffect by allowing for precise control over when the effect should run and when it should be cleaned up.
Changes Made
- Added TypeScript type definitions for the callback functions used in the hook.
- Implemented the
useEffectTillhook, including tracking if the effect has already run and handling cleanup. - Added internal comments to enhance code readability and understanding.
Usage Example
useEffectTill((done) => {
if (data) {
// Do something.
done();
}
}, [data]);
Why
The useEffectTill hook fills a gap in the React ecosystem by offering developers a way to execute effects with precise control over their lifecycle. It enhances code readability and reduces potential bugs related to effect cleanup.
How to Test
- Apply the
useEffectTillhook in a React component. - Write tests to cover scenarios where the effect should and should not run.
- Verify that cleanup occurs correctly once the effect is marked as done.
Additional Notes
- This implementation aligns with best practices in React development.
- The code includes appropriate TypeScript typings for a seamless integration into TypeScript projects.
⚠️ No Changeset found
Latest commit: 5df394e57937add3ba1a6b761ec75682c967604c
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Someone is attempting to deploy a commit to a Personal Account owned by @juliencrn on Vercel.
@juliencrn first needs to authorize it.
I think useEffectUntil is a better name if this is being added. "Til" is a contraction of "until" anyway (and mis-spelt as "till" here).