datahookinc / trigger

An opinionated React state management system based on data-oriented design principles
0 stars 0 forks source link

useLoadData that allows loading content into multiple tables and returning an object #71

Open datahookinc opened 1 year ago

datahookinc commented 1 year ago
const {
    data: content,
    status,
    error,
} = tables.useLoadData<{ folders: FolderType[], files: FileType[], flows: FlowType[] }>(async () => {
    const { data } = await getData<{ folders: FolderType[], files: FileType[], flows: FlowType[] }>(`/folder/${uuid}`, 'GET');
    return data;
});
datahookinc commented 1 year ago

Needs to have status and error indicators as well.

datahookinc commented 1 year ago

Look at useQueries in react-query for inspiration: likely just an array of promises that handle adding to the store themselves.

For instance:

tables.useLoadData([
   getData('/mydata').then(d => tables.cats.insertRows(d)),
   getData('/myotherdata').then(d => tables.other.insertRows(d)),
]);