UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

55 lines 2.04 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; 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 var WithListContext = function (_a) { var empty = _a.empty, loading = _a.loading, offline = _a.offline, error = _a.error, render = _a.render, children = _a.children, props = __rest(_a, ["empty", "loading", "offline", "error", "render", "children"]); var context = useListContextWithProps(props); var data = context.data, total = context.total, isPaused = context.isPaused, isPending = context.isPending, isPlaceholderData = context.isPlaceholderData, errorState = context.error; 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