loadFiles()
Description
Gets a promise with an array of files objectsinfo
The loadFiles() method is a part of the RestDataProvider service intended for working with the server
Usage
loadFiles(
id?: string
): Promise<obj[]>
Parameters
id- (optional) the id of a folder where items will be loaded (which is a path to the folder)
Returns
The loadFiles() method sends a request to the server by the GET method and returns a promise with the files data (an array of files). For an example of the data object, see the data property description.
Examples
import { useEffect, useState, useMemo } from "react";
import { RestDataProvider } from "@svar-ui/filemanager-data-provider";
import { Filemanager } from "@svar-ui/react-filemanager";
const url = "https://some-backend-url";
export default function ExampleFileManager() {
const restProvider = useMemo(() => new RestDataProvider(url), []);
const [data, setData] = useState([]);
// init is passed to the Filemanager component and will be called with the API instance
const init = (api) => {
api.setNext(restProvider);
// loadFiles returns a Promise with an array of files
restProvider.loadFiles().then((files) => {
setData(files);
});
};
// Optionally, you can pre-load files on component mount:
useEffect(() => {
restProvider.loadFiles().then((files) => setData(files));
}, [restProvider]);
return <Filemanager init={init} data={data} />;
}
Related articles: