mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
feat(useFirstMountState): hook to track if render is first; feat(useRendersCount): hook to track renders count; refactor(useUpdateEffect): now uses useFirstMountState hook; refactor(usePreviousDistinct): now uses with useFirstMountState hook; docs: update readme;
14 lines
219 B
TypeScript
14 lines
219 B
TypeScript
import { useRef } from 'react';
|
|
|
|
export function useFirstMountState(): boolean {
|
|
const isFirst = useRef(true);
|
|
|
|
if (isFirst.current) {
|
|
isFirst.current = false;
|
|
|
|
return true;
|
|
}
|
|
|
|
return isFirst.current;
|
|
}
|