TelegramPWA/src/hooks/useLayoutEffectWithPrevDeps.ts
Alexander Zinchuk 3afcde3217 Initial commit
2021-04-09 14:11:51 +03:00

12 lines
462 B
TypeScript

import { useLayoutEffect } from '../lib/teact/teact';
import usePrevious from './usePrevious';
export default <T extends any[], PT = T>(cb: (args: PT) => void, dependencies: T) => {
const prevDeps = usePrevious<T>(dependencies);
return useLayoutEffect(() => {
// @ts-ignore (workaround for "could be instantiated with a different subtype" issue)
cb(prevDeps || []);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, dependencies);
};