Module exposing: useUpdateEffect
// Source: https://github.com/keycloak/keycloak | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { DependencyList, EffectCallback, useEffect, useRef } from "react";
/**
* A `useEffect` hook that only triggers on updates, not on initial render.
*/
export function useUpdateEffect(effect: EffectCallback, deps?: DependencyList) {
const didMount = useRef(false);
useEffect(() => {
if (didMount.current) {
return effect();
}
didMount.current = true;
}, deps);
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key