@ariakit/react-core
Version:
Ariakit React core
60 lines (47 loc) • 2.29 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
var _PXZUDDVScjs = require('./PXZUDDVS.cjs');
var _RDNUVX4Vcjs = require('./RDNUVX4V.cjs');
var _4KGS3DOWcjs = require('./4KGS3DOW.cjs');
// src/form/form-store.ts
var _formstore = require('@ariakit/core/form/form-store'); var Core = _interopRequireWildcard(_formstore);
var _react = require('react');
function useFormStoreProps(store, update, props) {
store = _PXZUDDVScjs.useCollectionStoreProps.call(void 0, store, update, props);
_RDNUVX4Vcjs.useStoreProps.call(void 0, store, props, "values", "setValues");
_RDNUVX4Vcjs.useStoreProps.call(void 0, store, props, "errors", "setErrors");
_RDNUVX4Vcjs.useStoreProps.call(void 0, store, props, "touched", "setTouched");
const useValue = _react.useCallback.call(void 0,
(name) => _RDNUVX4Vcjs.useStoreState.call(void 0, store, () => store.getValue(name)),
[store]
);
const useValidate = _react.useCallback.call(void 0,
(callback) => {
callback = _4KGS3DOWcjs.useEvent.call(void 0, callback);
const items = _RDNUVX4Vcjs.useStoreState.call(void 0, store, "items");
_react.useEffect.call(void 0, () => store.onValidate(callback), [items, callback]);
},
[store]
);
const useSubmit = _react.useCallback.call(void 0,
(callback) => {
callback = _4KGS3DOWcjs.useEvent.call(void 0, callback);
const items = _RDNUVX4Vcjs.useStoreState.call(void 0, store, "items");
_react.useEffect.call(void 0, () => store.onSubmit(callback), [items, callback]);
},
[store]
);
return _react.useMemo.call(void 0,
() => ({
...store,
useValue,
useValidate,
useSubmit
}),
[store, useValue, useValidate, useSubmit]
);
}
function useFormStore(props = {}) {
const [store, update] = _RDNUVX4Vcjs.useStore.call(void 0, Core.createFormStore, props);
return useFormStoreProps(store, update, props);
}
exports.useFormStoreProps = useFormStoreProps; exports.useFormStore = useFormStore;