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.cjs CHANGED
@@ -937,6 +937,16 @@ function defaults(first, ...more) {
937
937
  }, first);
938
938
  }
939
939
 
940
+ //#endregion
941
+ //#region src/hooks/useLatestRef.ts
942
+ function useLatestRef(value) {
943
+ const latestValue = (0, react.useRef)(value);
944
+ (0, react.useEffect)(() => {
945
+ latestValue.current = value;
946
+ }, [value]);
947
+ return latestValue;
948
+ }
949
+
940
950
  //#endregion
941
951
  //#region src/components/dateInput.tsx
942
952
  const className$1 = "schummar-table-date-input";
@@ -962,7 +972,9 @@ function buildDate(value, baseDate = /* @__PURE__ */ new Date()) {
962
972
  function DateInput({ value, onChange, locale }) {
963
973
  const id = (0, react.useMemo)(() => (0, nanoid.nanoid)(), []);
964
974
  const [localValue, setLocalValue] = (0, react.useState)();
975
+ const latestValue = useLatestRef(value);
965
976
  const commit = (0, react.useMemo)(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
977
+ if (value$1 !== latestValue.current) return;
966
978
  const date = buildDate(localValue$1, value$1 ?? void 0);
967
979
  setLocalValue(void 0);
968
980
  onChange$1(isNaN(date.getTime()) ? null : date);
@@ -1057,7 +1069,9 @@ function buildTime(value, baseDate = /* @__PURE__ */ new Date()) {
1057
1069
  function TimeInput({ value, onChange, locale, showSeconds = true }) {
1058
1070
  const id = (0, react.useMemo)(() => (0, nanoid.nanoid)(), []);
1059
1071
  const [localValue, setLocalValue] = (0, react.useState)();
1072
+ const latestValue = useLatestRef(value);
1060
1073
  const commit = (0, react.useMemo)(() => debounce((localValue$1 = {}, value$1, onChange$1) => {
1074
+ if (value$1 !== latestValue.current) return;
1061
1075
  const date = buildTime(localValue$1, value$1 ?? void 0);
1062
1076
  setLocalValue(void 0);
1063
1077
  onChange$1(isNaN(date.getTime()) ? null : date);