react-say-fork
Version:
# Goal and TODOs * Add Typescript support * Make compononents style-customizable
25 lines (24 loc) • 713 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
function useImmediateEffect(fn, deps) {
const unsubscribeRef = (0, react_1.useRef)({
first: true,
id: Math.random().toString(36).substr(2, 5),
unsubscribe: fn()
});
(0, react_1.useEffect)(() => {
const { current } = unsubscribeRef;
if (!current.first) {
current.unsubscribe = fn();
}
else {
current.first = false;
}
return () => {
current.unsubscribe && current.unsubscribe();
current.unsubscribe = null;
};
}, deps);
}
exports.default = useImmediateEffect;