UNPKG

ra-core

Version:

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

49 lines 1.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePickSortContext = exports.ListSortContext = void 0; var react_1 = require("react"); var pick_js_1 = __importDefault(require("lodash/pick.js")); /** * Context to store the sort part of the useListController() result. * * Use the useListSortContext() hook to read the context. That's what many * List components do in react-admin (e.g. <SortButton>). * * @typedef {Object} ListSortContextValue * @prop {Object} sort a sort object { field, order }, e.g. { field: 'date', order: 'DESC' } * @prop {Function} setSort a callback to change the sort, e.g. setSort({ field: 'name', order: 'ASC' }) * @prop {string} resource the resource name, deduced from the location. e.g. 'posts' * * @typedef Props * @prop {ListSortContextValue} value * * @param {Props} * * @see useListController * @see useListSortContext * * @example * * import { useListController, usePickSortContext, ListSortContext } from 'ra-core'; * * const List = props => { * const controllerProps = useListController(props); * return ( * <ListSortContext.Provider value={usePickSortContext(controllerProps)}> * ... * </ListSortContext.Provider> * ); * }; */ exports.ListSortContext = (0, react_1.createContext)(undefined); var usePickSortContext = function (context) { return (0, react_1.useMemo)(function () { return (0, pick_js_1.default)(context, ['sort', 'setSort', 'resource']); }, // eslint-disable-next-line react-hooks/exhaustive-deps [context.sort, context.setSort]); }; exports.usePickSortContext = usePickSortContext; exports.ListSortContext.displayName = 'ListSortContext'; //# sourceMappingURL=ListSortContext.js.map