schummar-table 0.48.0 → 0.48.1

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
@@ -931,6 +931,16 @@ function defaults(first, ...more) {
931
931
  }, first);
932
932
  }
933
933
 
934
+ //#endregion
935
+ //#region src/hooks/useLatestRef.ts
936
+ function useLatestRef(value) {
937
+ const latestValue = useRef(value);
938
+ useEffect(() => {
939
+ latestValue.current = value;
940
+ }, [value]);
941
+ return latestValue;
942
+ }
943
+
934
944
  //#endregion
935
945
  //#region src/components/dateInput.tsx
936
946
  const className$1 = "schummar-table-date-input";
@@ -956,7 +966,9 @@ function buildDate(value, baseDate = /* @__PURE__ */ new Date()) {
956
966
  function DateInput({ value, onChange, locale }) {
957
967
  const id = useMemo(() => nanoid(), []);
958
968
  const [localValue, setLocalValue] = useState();
969
+ const latestValue = useLatestRef(value);
959
970
  const commit = useMemo(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
971
+ if (value$1 !== latestValue.current) return;
960
972
  const date = buildDate(localValue$1, value$1 ?? void 0);
961
973
  setLocalValue(void 0);
962
974
  onChange$1(isNaN(date.getTime()) ? null : date);
@@ -1051,7 +1063,9 @@ function buildTime(value, baseDate = /* @__PURE__ */ new Date()) {
1051
1063
  function TimeInput({ value, onChange, locale, showSeconds = true }) {
1052
1064
  const id = useMemo(() => nanoid(), []);
1053
1065
  const [localValue, setLocalValue] = useState();
1066
+ const latestValue = useLatestRef(value);
1054
1067
  const commit = useMemo(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
1068
+ if (value$1 !== latestValue.current) return;
1055
1069
  const date = buildTime(localValue$1, value$1 ?? void 0);
1056
1070
  setLocalValue(void 0);
1057
1071
  onChange$1(isNaN(date.getTime()) ? null : date);