press-pix
Version:
基于 PixUI 的 Press 组件库
32 lines (25 loc) • 727 B
text/typescript
import { useState, useRef } from 'preact/hooks';
export { showToast, toast } from './command';
export function useToast(durationParams = 2000) {
const [showToast, setShowToast] = useState<{show: boolean; text?: string}>({
show: false,
text: '',
});
const toastTimer = useRef<any>(null);
const onShowToast = (text, duration = durationParams) => {
setShowToast({ show: true, text });
clearTimeout(toastTimer.current);
toastTimer.current = setTimeout(() => {
setShowToast({ show: false, text: '' });
}, duration);
};
const handleToastClick = () => {
console.log('handleToastClick');
};
return {
showToast,
setShowToast,
onShowToast,
handleToastClick,
};
}