mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 00:14:25 +00:00
22 lines
555 B
JavaScript
22 lines
555 B
JavaScript
import { useState, useCallback } from 'react';
|
|
import { fetchFileList } from '../services/api';
|
|
|
|
export const useFileList = () => {
|
|
const [files, setFiles] = useState([]);
|
|
|
|
const loadFileList = useCallback(async () => {
|
|
try {
|
|
const fileList = await fetchFileList();
|
|
if (Array.isArray(fileList)) {
|
|
setFiles(fileList);
|
|
} else {
|
|
throw new Error('File list is not an array');
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load file list:', error);
|
|
}
|
|
}, []);
|
|
|
|
return { files, loadFileList };
|
|
};
|