buster/apps/web/src/hooks/useMount.ts

22 lines
497 B
TypeScript
Raw Normal View History

2025-03-08 07:02:56 +08:00
'use client';
2025-07-30 05:44:10 +08:00
import { useEffect, useState } from 'react';
2025-03-08 07:02:56 +08:00
/**
* Hook that executes a callback when a component mounts.
* @param callback Function to be called on mount
*/
export const useMount = (callback: () => void): void => {
useEffect(() => {
callback();
}, []); // Empty dependency array means this runs once on mount
};
2025-07-30 05:44:10 +08:00
export const useMounted = () => {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
return mounted;
};