
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
use-better-effect
Advanced tools
A wrapper around React.useEffect
but with improved API
With Yarn:
yarn add use-better-effect
With npm:
npm install --save use-better-effect
useEffect
is a powerful tool but the API has some gotchas. See the following examples:
// someFn runs on every render
useEffect(() => someFn());
// someFn only run on mount
useEffect(() => someFn(), []);
// someFn rerun when a or b changes
useEffect(() => someFn(), [a, b]);
// the returned function of the passed in callback function is called on mount.
useEffect(() => {
someFn();
return () => anotherFn();
}, [a, b]);
These implicit behaviors are hard to understand by just looking at the code.
useBetterEffect
uses typescript function overloading to improve the developer experience when using the effect for different conditions. There are 3 supports run conditions:
For ON_MOUNT
and EVERY_RENDER
, passing in dependencies will result in a type error and useBetterEffect
auto computes the dependency argument as []
and undefined
respectively.
The cleanup function is passing as an explict optional arugment.
import { useBetterEffect } from "use-better-effect";
useBetterEffect({
callbackFn: () => console.log("yay better"),
cleanupFn: () => console.log("so fresh and so clean"),
runCondition: "ON_MOUNT",
});
useBetterEffect({
callbackFn: () => console.log("yay better"),
cleanupFn: () => console.log("so fresh and so clean"),
runCondition: "EVERY_RENDER",
});
useBetterEffect({
callbackFn: () => console.log("yay better"),
cleanupFn: () => console.log("so fresh and so clean"),
runCondition: "DEPENDENCIES_CHANGED",
dependencies: [count],
});
FAQs
A wrapper around React.useEffect with improved API
The npm package use-better-effect receives a total of 0 weekly downloads. As such, use-better-effect popularity was classified as not popular.
We found that use-better-effect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.