Skip to content

Instantly share code, notes, and snippets.

@kasper573
Created July 19, 2019 12:12
Show Gist options
  • Save kasper573/f85da313e9fedd135edd899d5a7ebe58 to your computer and use it in GitHub Desktop.
Save kasper573/f85da313e9fedd135edd899d5a7ebe58 to your computer and use it in GitHub Desktop.
import { EffectCallback, useEffect } from 'react';
export const usePureEffect = <T extends EffectCallbackWithParams>(
effect: T,
...params: Parameters<T>
) => useEffect(() => effect.apply(null, params), params);
type EffectCallbackWithParams = (...args: any) => ReturnType<EffectCallback>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment