ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
43 lines • 1.3 kB
JavaScript
import { useListContextWithProps } from "./useListContextWithProps.js";
/**
* Render prop version of useListContextWithProps
*
* @example
* const BookList = () => (
* <List>
* <WithListContext render={({ data }) => (
* <ul>
* {data && data.map(record => (
* <li key={record.id}>{record.title}</li>
* ))}
* </ul>
* )} />
* </List>
* );
*/
export const WithListContext = ({ empty, loading, offline, error, render, children, ...props }) => {
const context = useListContextWithProps(props);
const { data, total, isPaused, isPending, isPlaceholderData, error: errorState, } = context;
if (!isPaused && isPending && loading !== false && loading !== undefined) {
return loading;
}
if (isPaused &&
(isPending || isPlaceholderData) &&
offline !== false &&
offline !== undefined) {
return offline;
}
if (errorState && error !== false && error !== undefined) {
return error;
}
if ((data == null || data.length === 0 || total === 0) &&
empty !== false &&
empty !== undefined) {
return empty;
}
if (render) {
return render(context);
}
return children;
};
//# sourceMappingURL=WithListContext.js.map