@del-wang/react-unstrict
v1.2.0
Published
✂️ Bypass React StrictMode double execution for consistent development behavior
Maintainers
Readme
@del-wang/react-unstrict
✂️ Bypass React StrictMode double execution for consistent development behavior.
Why?
React StrictMode double-invokes effects in development to detect side effects. This package ensures your code runs only once, maintaining consistency between development and production.
Installation
npm install @del-wang/react-unstrictGet Started
useUnStrictEffect
import { useUnStrictEffect } from "@del-wang/react-unstrict";
function Component() {
useUnStrictEffect(() => {
// Runs once, even in StrictMode
console.log("API call");
return () => console.log("Cleanup");
}, []);
return <div>Component</div>;
}useUnStrictRun
import { useUnStrictRun } from "@del-wang/react-unstrict";
function Component() {
useUnStrictRun(() => {
// Runs once per build, even though React calls build twice in dev mode
console.log("Build logic executed");
});
return <div>Component</div>;
}License
MIT © Del Wang
