Skip to content

Instantly share code, notes, and snippets.

@saltycrane
Created May 3, 2019 23:05
Show Gist options
  • Save saltycrane/86fd57ba4bd4148cd163f68479e71f1a to your computer and use it in GitHub Desktop.
Save saltycrane/86fd57ba4bd4148cd163f68479e71f1a to your computer and use it in GitHub Desktop.
export function useWhyCallback<T extends (...args: any[]) => any>(
callback: T,
deps: React.DependencyList,
name = "",
) {
useWhyDidYouUpdate(name, deps);
return useCallback(callback, deps);
}
export function useWhyEffect(
callback: React.EffectCallback,
deps: React.DependencyList,
name = "",
) {
useWhyDidYouUpdate(name, deps);
return useEffect(callback, deps);
}
export function useWhyMemo<T>(
callback: () => T,
deps: React.DependencyList,
name = "",
) {
useWhyDidYouUpdate(name, deps);
return useMemo(callback, deps);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment