ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
33 lines • 1.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePickSaveContext = void 0;
const react_1 = require("react");
const pick_js_1 = __importDefault(require("lodash/pick.js"));
/**
* This hook extracts the `save`, `saving` and mutationMode properties from either the `CreateContext` or `EditContext`. This ensures the `SaveContext` doesn't rerender when those two contexts have other properties changes.
*/
const usePickSaveContext = (context) => {
const value = (0, react_1.useMemo)(() => (0, pick_js_1.default)(context, [
'save',
'saving',
'mutationMode',
'registerMutationMiddleware',
'unregisterMutationMiddleware',
]),
/* eslint-disable react-hooks/exhaustive-deps */
[
context.save,
context.saving,
context.mutationMode,
context.registerMutationMiddleware,
context.unregisterMutationMiddleware,
]
/* eslint-enable react-hooks/exhaustive-deps */
);
return value;
};
exports.usePickSaveContext = usePickSaveContext;
//# sourceMappingURL=usePickSaveContext.js.map