@juantroconisf/lib 2.3.2 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -185,8 +185,7 @@ function useValidation() {
185
185
 
186
186
  // src/hooks/useFormChange.tsx
187
187
  function useFormChange(initialObj) {
188
- const [state, setState] = (0, import_react.useState)(initialObj), [touched, setTouched] = (0, import_react.useState)(allToValue(initialObj, false)), { getValidation } = useValidation();
189
- let errors2 = allToValue(initialObj, false);
188
+ const [state, setState] = (0, import_react.useState)(initialObj), [touched, setTouched] = (0, import_react.useState)(allToValue(initialObj, false)), { getValidation } = useValidation(), errors2 = (0, import_react.useRef)(allToValue(initialObj, false));
190
189
  const onChange = ({
191
190
  target: { id, value }
192
191
  }) => setState(handleNestedChange({ state, id, value })), onBlur = ({ target: { id } }) => setTouched(handleNestedChange({ state: touched, id, value: true })), resetForm = () => {
@@ -195,8 +194,8 @@ function useFormChange(initialObj) {
195
194
  };
196
195
  function register(id, validations, errorMessages) {
197
196
  const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
198
- errors2 = handleNestedChange({
199
- state: errors2,
197
+ errors2.current = handleNestedChange({
198
+ state: errors2.current,
200
199
  id,
201
200
  value: hasValidations ? !inputValidations.isValid : false
202
201
  });
@@ -211,7 +210,7 @@ function useFormChange(initialObj) {
211
210
  }
212
211
  const hasInvalidValues = () => {
213
212
  setTouched(allToValue(touched, true));
214
- return JSON.stringify(errors2).includes(":true");
213
+ return JSON.stringify(errors2.current).includes(":true");
215
214
  };
216
215
  return {
217
216
  onChange,
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/hooks/useFormChange.tsx
9
- import { useState } from "react";
9
+ import { useState, useRef } from "react";
10
10
 
11
11
  // types/errors.ts
12
12
  var NextUIError = class {
@@ -167,8 +167,7 @@ function useValidation() {
167
167
 
168
168
  // src/hooks/useFormChange.tsx
169
169
  function useFormChange(initialObj) {
170
- const [state, setState] = useState(initialObj), [touched, setTouched] = useState(allToValue(initialObj, false)), { getValidation } = useValidation();
171
- let errors2 = allToValue(initialObj, false);
170
+ const [state, setState] = useState(initialObj), [touched, setTouched] = useState(allToValue(initialObj, false)), { getValidation } = useValidation(), errors2 = useRef(allToValue(initialObj, false));
172
171
  const onChange = ({
173
172
  target: { id, value }
174
173
  }) => setState(handleNestedChange({ state, id, value })), onBlur = ({ target: { id } }) => setTouched(handleNestedChange({ state: touched, id, value: true })), resetForm = () => {
@@ -177,8 +176,8 @@ function useFormChange(initialObj) {
177
176
  };
178
177
  function register(id, validations, errorMessages) {
179
178
  const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
180
- errors2 = handleNestedChange({
181
- state: errors2,
179
+ errors2.current = handleNestedChange({
180
+ state: errors2.current,
182
181
  id,
183
182
  value: hasValidations ? !inputValidations.isValid : false
184
183
  });
@@ -193,7 +192,7 @@ function useFormChange(initialObj) {
193
192
  }
194
193
  const hasInvalidValues = () => {
195
194
  setTouched(allToValue(touched, true));
196
- return JSON.stringify(errors2).includes(":true");
195
+ return JSON.stringify(errors2.current).includes(":true");
197
196
  };
198
197
  return {
199
198
  onChange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",