@rainbow-oh/yee-c 0.4.2 → 0.4.3
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/cjs/Form/form-store.js +3 -0
- package/dist/cjs/Form/hooks/useWatch.js +4 -2
- package/dist/cjs/TextArea/textarea.js +0 -1
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Form/form-store.js +4 -0
- package/dist/esm/Form/hooks/useWatch.js +7 -2
- package/dist/esm/TextArea/textarea.js +0 -1
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Form/form-store.ts +4 -0
- package/src/Form/hooks/useWatch.ts +9 -2
- package/src/TextArea/textarea.tsx +0 -2
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/Form/form-store.ts
CHANGED
|
@@ -494,6 +494,10 @@ export class FormStore {
|
|
|
494
494
|
} else {
|
|
495
495
|
this.store = { ...this.store, [normalizedName]: value };
|
|
496
496
|
}
|
|
497
|
+
// When value is not undefined, notify watchers to trigger re-rendering of useWatch
|
|
498
|
+
if (value !== undefined) {
|
|
499
|
+
this.notifyWatchers(normalizedName);
|
|
500
|
+
}
|
|
497
501
|
}
|
|
498
502
|
}
|
|
499
503
|
entity.onStoreChange?.();
|
|
@@ -27,10 +27,17 @@ function useWatch<T = any>(
|
|
|
27
27
|
Array.isArray(namePath) ? namePath.join('.') : (namePath as string),
|
|
28
28
|
);
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const update = () => {
|
|
31
31
|
const newValue = getWatchedValue();
|
|
32
32
|
setValue((prev) => (prev === newValue ? prev : newValue));
|
|
33
|
-
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const unsubscribe = formInstance.subscribe(namePath, update);
|
|
36
|
+
// Re-read immediately after subscribing: the parent's useWatch captured its
|
|
37
|
+
// initial snapshot before child Form.Field wrote its initialValue, and the
|
|
38
|
+
// subscription may not yet exist when that write happens. This covers the gap.
|
|
39
|
+
update();
|
|
40
|
+
|
|
34
41
|
return unsubscribe;
|
|
35
42
|
}, [formInstance, namePath]);
|
|
36
43
|
|