ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
34 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useArrayInput = void 0;
const react_1 = require("react");
const ArrayInputContext_1 = require("./ArrayInputContext.cjs");
/**
* A hook to access an array input methods as provided by react-hook-form.
* Useful to create custom array input iterators.
* @see {ArrayInput}
* @see https://react-hook-form.com/docs/usefieldarray
*/
const useArrayInput = (props) => {
const context = (0, react_1.useContext)(ArrayInputContext_1.ArrayInputContext);
const memo = (0, react_1.useMemo)(() => ({
append: props?.append,
fields: props?.fields,
insert: props?.insert,
move: props?.move,
prepend: props?.prepend,
remove: props?.remove,
replace: props?.replace,
swap: props?.swap,
update: props?.update,
}), [props]);
if (props?.fields) {
return memo;
}
if (!context) {
throw new Error('useArrayInput must be used inside an ArrayInputContextProvider');
}
return context;
};
exports.useArrayInput = useArrayInput;
//# sourceMappingURL=useArrayInput.js.map