Skip to content

Commit

Permalink
[@mantine/hooks] use-did-update: Add status reset for double effect c…
Browse files Browse the repository at this point in the history
…all in strict mode (#1870)

* [@mantine/hooks] use-did-update: Optimize fast refresh

* chore: eslint fix
  • Loading branch information
u3u committed Aug 16, 2022
1 parent 72555ad commit 486bd30
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/mantine-hooks/src/use-did-update/use-did-update.ts
@@ -1,13 +1,22 @@
import { useEffect, useRef, EffectCallback } from 'react';
import { useEffect, useRef } from 'react';

export function useDidUpdate(fn: EffectCallback, dependencies?: any[]) {
export function useDidUpdate(fn: React.EffectCallback, dependencies?: React.DependencyList) {
const mounted = useRef(false);

// for react-refresh
useEffect(
() => () => {
mounted.current = false;
},
[]
);

// eslint-disable-next-line consistent-return
useEffect(() => {
if (mounted.current) {
fn();
} else {
mounted.current = true;
return fn();
}

mounted.current = true;
}, dependencies);
}

0 comments on commit 486bd30

Please sign in to comment.