@primer/react
Version:
An implementation of GitHub's Primer Design System using React
22 lines (21 loc) • 867 B
JavaScript
import { useEffect } from "react";
//#region src/internal/hooks/useDevOnlyEffect.ts
/**
* Runs an effect only in development. Wrapping `useEffect` in a regular hook
* with an outer `__DEV__` guard keeps the production cost to zero (the entire
* call is dropped by the consumer's `process.env.NODE_ENV` replacement) while
* centralising the `eslint-disable react-hooks/rules-of-hooks` to one place
* instead of every call site.
*
* `exhaustive-deps` is wired up to also check call sites of this hook via
* `additionalEffectHooks` in `eslint.config.mjs`, so callers get the same
* deps lint they would for a plain `useEffect`.
*
* @param effect The effect callback to run in development.
* @param deps Dependency list, same semantics as `useEffect`.
*/
const useDevOnlyEffect = (effect, deps) => {
useEffect(effect, deps);
};
//#endregion
export { useDevOnlyEffect };