UNPKG

react-rooks

Version:

Store management for React and React Native with simple hooks !

29 lines (28 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createZodRook = void 0; const create_1 = require("./create"); const createZodRook = (schema, { storeReducer: customStoreReducer, onValidationError, } = {}) => { console.log("Default store:", schema); const defaultStore = schema.parse({}); const storeReducer = (values, currentStore) => { let valuesToValidate; if (customStoreReducer) { valuesToValidate = customStoreReducer(values, currentStore); } else { valuesToValidate = Object.assign(Object.assign({}, currentStore), values); } const parsedStore = schema.safeParse(valuesToValidate); if (!parsedStore.success) { onValidationError === null || onValidationError === void 0 ? void 0 : onValidationError(parsedStore.error, valuesToValidate, currentStore); return currentStore; } return parsedStore.data; }; return (0, create_1.createRook)({ defaultStore, storeReducer, }); }; exports.createZodRook = createZodRook;