UNPKG

ra-core

Version:

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

47 lines 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WithListContext = void 0; const useListContextWithProps_1 = require("./useListContextWithProps.cjs"); /** * 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> * ); */ const WithListContext = ({ empty, loading, offline, error, render, children, ...props }) => { const context = (0, useListContextWithProps_1.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; }; exports.WithListContext = WithListContext; //# sourceMappingURL=WithListContext.js.map