Files
Shortumation/webapp/src/apiService/core.ts
T
ari 5e345d20e5 - clean up
- origins
2022-04-15 15:50:33 -04:00

26 lines
668 B
TypeScript

import { useEffect } from 'react';
import { useDefaultApiState, makeReloadAutomations } from './util';
import { AutomationAPI } from './automations';
export type ApiService = ReturnType<typeof useAPIService>;
export const useAPIService = (
automationAPI: AutomationAPI
) => {
// state
const [state, setState] = useDefaultApiState();
const { reload, wrapCall } = makeReloadAutomations(automationAPI, state, setState);
// initial load of autos
useEffect(() => {
reload();
// eslint-disable-next-line
}, []);
return {
state,
removeAutomation: wrapCall(automationAPI.remove),
updateAutomation: wrapCall(automationAPI.update),
}
}