Custom Hooks Style Guide
ShouldWhen writing custom hooks follow guidelines as described in Code Ordering Style.
On top of code ordering, the following guildlines should also be followed
- return object should not have any inline functions. Functions on the return object should be declared above the return statement like in the following example.
-
export const useFileUploadApi = () => {
const deleteAllFailedFileUploadsAsync = async () => {
const resp: AxiosResponse = await Api.delete('api/FileUpload/Failed/All');
return resp.data as UtopiaUploadFileResponse[];
};
const deleteFailedFileUploadAsync = async (nodeId: string, uploadIdentifier: string) => {
const resp: AxiosResponse = await Api.delete(`api/FileUpload/Failed?nodeId=${nodeId}&uploadIdentifier=${uploadIdentifier}`);
return resp.data as UtopiaUploadFileResponse[];
};
const queryFailedFileUploadsAsync = async (start: number, count: number) => {
const resp: AxiosResponse = await Api.get(`api/FileUpload/Failed?start=${start}&count=${count}`);
return resp.data as UtopiaUploadFileResponse[];
};
return {
deleteAllFailedFileUploadsAsync,
deleteFailedFileUploadAsync,
queryFailedFileUploadsAsync
};
};
-