@intility/bifrost-react
Version:
React library for Intility's design system, Bifrost.
33 lines (32 loc) • 780 B
JavaScript
import { c as _c } from "react-compiler-runtime";
// https://github.com/reactjs/rfcs/pull/220
// https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
import React from "react";
function useEffectEvent(handler) {
const $ = _c(3);
const handlerRef = React.useRef(null);
let t0;
if ($[0] !== handler) {
t0 = () => {
handlerRef.current = handler;
};
$[0] = handler;
$[1] = t0;
} else {
t0 = $[1];
}
React.useInsertionEffect(t0);
let t1;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t1 = (...t2) => {
const args = t2;
const fn = handlerRef.current;
return fn?.(...args);
};
$[2] = t1;
} else {
t1 = $[2];
}
return t1;
}
export default React.useEffectEvent ?? useEffectEvent;