Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import React, { useMemo } from "react";
export function useDisplayIsNodata<T>({
dataSet,
isLoading,
isNodataComponent,
isNodata,
}: {
dataSet: T | null | undefined;
isLoading: boolean;
isNodataComponent: React.ReactNode;
isNodata?: boolean | ((dataSet: T | null | undefined) => boolean);
}): boolean {
const displayIsNodata = useMemo(() => {
// If loading or no nodata component, always return false
if (isLoading || !isNodataComponent) {
return false;
}
// Check custom nodata function
if (typeof isNodata === "function") {
return isNodata(dataSet);
}
// Check boolean override
if (typeof isNodata === "boolean") {
return isNodata;
}
// Check if array is empty
if (Array.isArray(dataSet)) {
return dataSet.length === 0;
}
// Default case
return false;
}, [isLoading, isNodataComponent, dataSet, isNodata]);
return displayIsNodata;
}
|