@carefrees/form-utils-react-hooks 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -1,9 +1,264 @@
1
- # 表单工具
2
-
3
- - [ ] 表单项
4
- - [ ] 隐藏表单项
5
- - [ ] 空表单项
6
- - [ ] list表单项
7
- - [ ] layout分组标题
8
- - [ ] 依赖项表单项更新
9
- - [ ] 通知表单项更新
1
+ # 公共hooks
2
+
3
+ ## 安装
4
+
5
+ ```bash
6
+ npm install @carefrees/form-utils-react-hooks # yarn add @carefrees/form-utils-react-hooks # pnpm add @carefrees/form-utils-react-hooks
7
+ ```
8
+
9
+ ## Form表单
10
+
11
+ - useForm: 初始化表单实例
12
+ - useFormInstance: 子项中获取表单实例
13
+ - useFormItem: 初始化表单项实例
14
+ - useFormItemInstance: 子项中获取表单项实例
15
+ - useFormList: 初始化表单List实例
16
+ - useFormListInstance: 子项中获取表单List实例
17
+ - useMultipleForm: 初始化 多表单收集 实例
18
+ - useMultipleFormInstance: 子项中获取 多表单收集 实例
19
+ - useWatch: 监听表单某个值变化
20
+ - useAttrs: 获取布局公共属性
21
+ - useFormItemParentName: 获取表单父级name
22
+ - useHtmlFor: 生成label标签的for属性
23
+
24
+ ### 注册
25
+
26
+ - useRegisterForm: 注册表单实例到多表单收集实例中
27
+ - useRegisterFormHideItem: 注册表单隐藏表单项到表单实例中
28
+ - useRegisterFormItem: 注册表单项到表单实例中
29
+ - useRegisterFormList: 注册表单List到表单实例中
30
+
31
+ ### Context
32
+
33
+ - FormInstanceContext: 表单实例
34
+ - FormItemInstanceContext: 表单项实例
35
+ - FormListInstanceContext: 表单List实例
36
+ - MultipleFormInstanceContext: 多表单收集实例
37
+ - FormItemParentNameContext: 表单父级name
38
+ - AttrsContext: 布局公共属性
39
+
40
+ ### Provider
41
+
42
+ - MultipleFormProvider: 多表单收集 Provider
43
+
44
+ ## 类型
45
+
46
+ ### useForm
47
+
48
+ ```ts
49
+ import { FormInstanceBase } from '@carefrees/form-utils';
50
+ /**表单实例 Context */
51
+ export declare const FormInstanceContext: import("react").Context<FormInstanceBase<any>>;
52
+ /**子项中获取表单实例*/
53
+ export declare function useFormInstance<T = any>(): FormInstanceBase<T>;
54
+ /**初始化表单实例*/
55
+ export declare function useForm<T = any>(form?: FormInstanceBase<T>): FormInstanceBase<T>;
56
+ ```
57
+
58
+ ### useFormItem
59
+
60
+ ```ts
61
+ import { FormItemInstanceBase } from '@carefrees/form-utils';
62
+ /**表单项实例 Context */
63
+ export declare const FormItemInstanceContext: import("react").Context<FormItemInstanceBase>;
64
+ /**子项中获取表单项实例*/
65
+ export declare const useFormItemInstance: () => FormItemInstanceBase;
66
+ /**s初始化 表单项实例*/
67
+ export declare const useFormItem: (formItem?: FormItemInstanceBase) => FormItemInstanceBase;
68
+ ```
69
+
70
+ ### useFormList
71
+
72
+ ```ts
73
+ import { FormListInstanceBase } from '@carefrees/form-utils';
74
+ /**表单List实例 Context */
75
+ export declare const FormListInstanceContext: import("react").Context<FormListInstanceBase>;
76
+ /**子项中获取表单List实例*/
77
+ export declare const useFormListInstance: () => FormListInstanceBase;
78
+ /**初始化 表单List实例*/
79
+ export declare const useFormList: (formList?: FormListInstanceBase) => FormListInstanceBase;
80
+
81
+ ```
82
+
83
+ ### useMultipleForm
84
+
85
+ ```ts
86
+ import { MultipleInstanceBase } from '@carefrees/form-utils';
87
+ /**多表单收集 Context */
88
+ export declare const MultipleFormInstanceContext: import("react").Context<MultipleInstanceBase>;
89
+ /**子项中获取 多表单收集 实例*/
90
+ export declare const useMultipleFormInstance: () => MultipleInstanceBase;
91
+ /**初始化 多表单收集 实例*/
92
+ export declare const useMultipleForm: (multipleForm?: MultipleInstanceBase) => MultipleInstanceBase;
93
+ export interface MultipleFormProviderProps {
94
+ children: React.ReactNode;
95
+ multipleForm?: MultipleInstanceBase;
96
+ }
97
+ /**多表单收集 Provider */
98
+ export declare const MultipleFormProvider: (props: MultipleFormProviderProps) => import("react").FunctionComponentElement<import("react").ProviderProps<MultipleInstanceBase>>;
99
+ ```
100
+
101
+ ### useWatch
102
+
103
+ ```ts
104
+ import { FormInstanceBase } from '@carefrees/form-utils';
105
+ export declare class WatchInstanceBase {
106
+ /**监听字段*/
107
+ name: string;
108
+ /**表单实例*/
109
+ form: FormInstanceBase;
110
+ /**老值*/
111
+ oldValue: any;
112
+ /**更新值*/
113
+ dispatch: (value: any) => void;
114
+ /**回调*/
115
+ callBack?: (value: any, form: FormInstanceBase) => void;
116
+ /**更新*/
117
+ updated: () => void;
118
+ }
119
+ /**
120
+ * 字段监听
121
+ */
122
+ export declare const useWatch: (name: string, form: FormInstanceBase, callBack?: (value: any, form: FormInstanceBase) => void) => [any, FormInstanceBase, WatchInstanceBase];
123
+
124
+ ```
125
+
126
+ ### useAttrs
127
+
128
+ ```ts
129
+ export interface AttrsOptions {
130
+ /**列数据*/
131
+ colCount?: number;
132
+ /**规则校验失败错误提示位置*/
133
+ errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
134
+ /**
135
+ * label显示模式
136
+ * @platform taro 支持 between
137
+ */
138
+ labelMode?: 'left' | 'top' | 'between' | 'hide';
139
+ /**是否显示label后的冒号*/
140
+ showColon?: boolean;
141
+ /**表单项 className*/
142
+ formItemClassName?: string;
143
+ /**表单项 style*/
144
+ formItemStyle?: React.CSSProperties;
145
+ /**表单项 label className*/
146
+ formItemLabelClassName?: string;
147
+ /**表单项 label style*/
148
+ formItemLabelStyle?: React.CSSProperties;
149
+ /**
150
+ * 输入框底部边框
151
+ * @platform taro
152
+ */
153
+ inputBordered?: boolean;
154
+ }
155
+ /**公共属性 Context */
156
+ export declare const AttrsContext: import("react").Context<AttrsOptions>;
157
+ /**子项中获取公共属性*/
158
+ export declare const useAttrs: () => AttrsOptions;
159
+ ```
160
+
161
+ ### useFormItemParentName
162
+
163
+ ```ts
164
+ export declare const FormItemParentNameContext: import("react").Context<{
165
+ name: string;
166
+ sort: string;
167
+ }>;
168
+ export interface FormItemParentNamOptions {
169
+ /**字段*/
170
+ name: string;
171
+ /**排序*/
172
+ sort?: string;
173
+ /**是否拼接父级字段*/
174
+ isJoinParentField?: boolean;
175
+ }
176
+ interface FormItemParentNameProviderProps extends Omit<FormItemParentNamOptions, 'isJoinParentField'> {
177
+ children?: React.ReactNode;
178
+ }
179
+ export declare const FormItemParentNameProvider: (props: FormItemParentNameProviderProps) => import("react").FunctionComponentElement<import("react").ProviderProps<{
180
+ name: string;
181
+ sort: string;
182
+ }>>;
183
+ /**表单项获取父级字段*/
184
+ export declare const useFormItemParentName: (options: FormItemParentNamOptions) => {
185
+ newName: string;
186
+ newSort: string;
187
+ parentItem: {
188
+ name: string;
189
+ sort: string;
190
+ };
191
+ parentName: string;
192
+ };
193
+ ```
194
+
195
+ ### useHtmlFor
196
+
197
+ ```ts
198
+ export declare const useHtmlFor: (suffix: string) => string;
199
+ ```
200
+
201
+ ### useRegisterForm
202
+
203
+ ```ts
204
+ import { FormInstanceBase } from '@carefrees/form-utils';
205
+ /**注册表单实例到多表单收集实例中*/
206
+ export declare const useRegisterForm: (form: FormInstanceBase, name?: string) => import("@carefrees/form-utils").MultipleInstanceBase;
207
+
208
+ ```
209
+
210
+ ### useRegisterFormHideItem
211
+
212
+ ```ts
213
+ import { RegisterFormItemOptions } from './register.FormItem';
214
+ interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rules'> {
215
+ }
216
+ /**注册表单隐藏表单项到表单实例中*/
217
+ export declare const useRegisterFormHideItem: (options: RegisterFormHideItemOptions) => {
218
+ form: import("@carefrees/form-utils").FormInstanceBase<any>;
219
+ isHide: any;
220
+ };
221
+ ```
222
+
223
+ ### useRegisterFormItem
224
+
225
+ ```ts
226
+ /**
227
+ * @description 注册组件
228
+ */
229
+ import { RuleInstanceBase } from '@carefrees/form-utils';
230
+ import type { RuleItem } from 'async-validator';
231
+ export interface RegisterFormItemOptions {
232
+ /**字段*/
233
+ name: string;
234
+ /**规则*/
235
+ rules?: RuleItem[];
236
+ /**排序值*/
237
+ sort?: string;
238
+ /**是否拼接父级字段*/
239
+ isJoinParentField?: boolean;
240
+ }
241
+ /**注册表单项到表单实例中*/
242
+ export declare const useRegisterFormItem: (options: RegisterFormItemOptions) => {
243
+ ruleInstance: RuleInstanceBase;
244
+ formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
245
+ form: import("@carefrees/form-utils").FormInstanceBase<any>;
246
+ parentName: string;
247
+ newName: string;
248
+ };
249
+ ```
250
+
251
+ ### useRegisterFormList
252
+
253
+ ```ts
254
+ import { RegisterFormItemOptions } from './register.FormItem';
255
+ export interface RegisterFormListOptions extends RegisterFormItemOptions {
256
+ }
257
+ /**注册表单List到表单实例中*/
258
+ export declare const useRegisterFormList: (options: RegisterFormListOptions) => {
259
+ ruleInstance: import("@carefrees/form-utils").RuleInstanceBase;
260
+ formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
261
+ formListInstance: import("@carefrees/form-utils").FormListInstanceBase;
262
+ };
263
+
264
+ ```
@@ -2,11 +2,10 @@ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
3
3
  import * as __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__ from "../useFormItemParentName.js";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__ from "../useForm.js";
5
- import * as __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__ from "../useUpdate.js";
6
5
  const useRegisterFormHideItem = (options)=>{
7
6
  const { name, sort, isJoinParentField = true } = options;
8
7
  const form = (0, __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__.useFormInstance)();
9
- const _update = (0, __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__.useUpdate)();
8
+ const [, setValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
10
9
  const { newName, newSort } = (0, __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__.useFormItemParentName)({
11
10
  name,
12
11
  sort,
@@ -14,8 +13,9 @@ const useRegisterFormHideItem = (options)=>{
14
13
  });
15
14
  const hideItemInstance = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormHideItemInstanceBase().ctor(newName)).current;
16
15
  const isHide = form.getFieldHideValue(newName);
16
+ hideItemInstance.preHideValue = isHide;
17
17
  hideItemInstance.instance = form;
18
- hideItemInstance.updated = _update.current;
18
+ hideItemInstance.updatedItem = setValue;
19
19
  hideItemInstance.sort = newSort;
20
20
  (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
21
21
  const unMount = form.registerFormHideItem(hideItemInstance);
@@ -1,6 +1,5 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
3
- import * as __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__ from "../useUpdate.js";
4
3
  import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__ from "../useForm.js";
5
4
  import * as __WEBPACK_EXTERNAL_MODULE__useFormItem_js_cd5761e5__ from "../useFormItem.js";
6
5
  import * as __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__ from "../useFormItemParentName.js";
@@ -12,6 +11,7 @@ const useRegisterFormItem = (options)=>{
12
11
  sort,
13
12
  isJoinParentField
14
13
  });
14
+ const [, setValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
15
15
  const ruleInstance = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.RuleInstanceBase()).current;
16
16
  (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>ruleInstance.ctor(newName, rules), [
17
17
  rules,
@@ -24,9 +24,8 @@ const useRegisterFormItem = (options)=>{
24
24
  formItemInstance.instance = form;
25
25
  formItemInstance.sort = newSort;
26
26
  formItemInstance.parentDataField = parentName;
27
- const _updated = (0, __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__.useUpdate)();
28
- formItemInstance.updated = _updated.current;
29
- ruleInstance.updated = _updated.current;
27
+ formItemInstance.updated = setValue;
28
+ ruleInstance.updated = setValue;
30
29
  (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
31
30
  const unMount = form.registerFormItem(formItemInstance);
32
31
  return ()=>unMount();
package/esm/index.d.ts CHANGED
@@ -9,5 +9,4 @@ export * from './hooks/useFormItemParentName';
9
9
  export * from './hooks/useFormList';
10
10
  export * from './hooks/useHtmlFor';
11
11
  export * from './hooks/useMultipleForm';
12
- export * from './hooks/useUpdate';
13
12
  export * from './hooks/useWatch';
package/esm/index.js CHANGED
@@ -9,5 +9,4 @@ export * from "./hooks/useFormItemParentName.js";
9
9
  export * from "./hooks/useFormList.js";
10
10
  export * from "./hooks/useHtmlFor.js";
11
11
  export * from "./hooks/useMultipleForm.js";
12
- export * from "./hooks/useUpdate.js";
13
12
  export * from "./hooks/useWatch.js";
@@ -30,11 +30,10 @@ const external_react_namespaceObject = require("react");
30
30
  const form_utils_namespaceObject = require("@carefrees/form-utils");
31
31
  const external_useFormItemParentName_js_namespaceObject = require("../useFormItemParentName.js");
32
32
  const external_useForm_js_namespaceObject = require("../useForm.js");
33
- const external_useUpdate_js_namespaceObject = require("../useUpdate.js");
34
33
  const useRegisterFormHideItem = (options)=>{
35
34
  const { name, sort, isJoinParentField = true } = options;
36
35
  const form = (0, external_useForm_js_namespaceObject.useFormInstance)();
37
- const _update = (0, external_useUpdate_js_namespaceObject.useUpdate)();
36
+ const [, setValue] = (0, external_react_namespaceObject.useState)({});
38
37
  const { newName, newSort } = (0, external_useFormItemParentName_js_namespaceObject.useFormItemParentName)({
39
38
  name,
40
39
  sort,
@@ -42,8 +41,9 @@ const useRegisterFormHideItem = (options)=>{
42
41
  });
43
42
  const hideItemInstance = (0, external_react_namespaceObject.useRef)(new form_utils_namespaceObject.FormHideItemInstanceBase().ctor(newName)).current;
44
43
  const isHide = form.getFieldHideValue(newName);
44
+ hideItemInstance.preHideValue = isHide;
45
45
  hideItemInstance.instance = form;
46
- hideItemInstance.updated = _update.current;
46
+ hideItemInstance.updatedItem = setValue;
47
47
  hideItemInstance.sort = newSort;
48
48
  (0, external_react_namespaceObject.useEffect)(()=>{
49
49
  const unMount = form.registerFormHideItem(hideItemInstance);
@@ -28,7 +28,6 @@ __webpack_require__.d(__webpack_exports__, {
28
28
  });
29
29
  const external_react_namespaceObject = require("react");
30
30
  const form_utils_namespaceObject = require("@carefrees/form-utils");
31
- const external_useUpdate_js_namespaceObject = require("../useUpdate.js");
32
31
  const external_useForm_js_namespaceObject = require("../useForm.js");
33
32
  const external_useFormItem_js_namespaceObject = require("../useFormItem.js");
34
33
  const external_useFormItemParentName_js_namespaceObject = require("../useFormItemParentName.js");
@@ -40,6 +39,7 @@ const useRegisterFormItem = (options)=>{
40
39
  sort,
41
40
  isJoinParentField
42
41
  });
42
+ const [, setValue] = (0, external_react_namespaceObject.useState)({});
43
43
  const ruleInstance = (0, external_react_namespaceObject.useRef)(new form_utils_namespaceObject.RuleInstanceBase()).current;
44
44
  (0, external_react_namespaceObject.useMemo)(()=>ruleInstance.ctor(newName, rules), [
45
45
  rules,
@@ -52,9 +52,8 @@ const useRegisterFormItem = (options)=>{
52
52
  formItemInstance.instance = form;
53
53
  formItemInstance.sort = newSort;
54
54
  formItemInstance.parentDataField = parentName;
55
- const _updated = (0, external_useUpdate_js_namespaceObject.useUpdate)();
56
- formItemInstance.updated = _updated.current;
57
- ruleInstance.updated = _updated.current;
55
+ formItemInstance.updated = setValue;
56
+ ruleInstance.updated = setValue;
58
57
  (0, external_react_namespaceObject.useEffect)(()=>{
59
58
  const unMount = form.registerFormItem(formItemInstance);
60
59
  return ()=>unMount();
package/lib/index.d.ts CHANGED
@@ -9,5 +9,4 @@ export * from './hooks/useFormItemParentName';
9
9
  export * from './hooks/useFormList';
10
10
  export * from './hooks/useHtmlFor';
11
11
  export * from './hooks/useMultipleForm';
12
- export * from './hooks/useUpdate';
13
12
  export * from './hooks/useWatch';
package/lib/index.js CHANGED
@@ -33,9 +33,6 @@ var __webpack_modules__ = {
33
33
  "./hooks/useMultipleForm": function(module) {
34
34
  module.exports = require("./hooks/useMultipleForm.js");
35
35
  },
36
- "./hooks/useUpdate": function(module) {
37
- module.exports = require("./hooks/useUpdate.js");
38
- },
39
36
  "./hooks/useWatch": function(module) {
40
37
  module.exports = require("./hooks/useWatch.js");
41
38
  }
@@ -149,16 +146,10 @@ var __webpack_exports__ = {};
149
146
  return _hooks_useMultipleForm__WEBPACK_IMPORTED_MODULE_10__[key];
150
147
  }).bind(0, __WEBPACK_IMPORT_KEY__);
151
148
  __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
152
- var _hooks_useUpdate__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__("./hooks/useUpdate");
153
- var __WEBPACK_REEXPORT_OBJECT__ = {};
154
- for(var __WEBPACK_IMPORT_KEY__ in _hooks_useUpdate__WEBPACK_IMPORTED_MODULE_11__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
155
- return _hooks_useUpdate__WEBPACK_IMPORTED_MODULE_11__[key];
156
- }).bind(0, __WEBPACK_IMPORT_KEY__);
157
- __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
158
- var _hooks_useWatch__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__("./hooks/useWatch");
149
+ var _hooks_useWatch__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__("./hooks/useWatch");
159
150
  var __WEBPACK_REEXPORT_OBJECT__ = {};
160
- for(var __WEBPACK_IMPORT_KEY__ in _hooks_useWatch__WEBPACK_IMPORTED_MODULE_12__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
161
- return _hooks_useWatch__WEBPACK_IMPORTED_MODULE_12__[key];
151
+ for(var __WEBPACK_IMPORT_KEY__ in _hooks_useWatch__WEBPACK_IMPORTED_MODULE_11__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
152
+ return _hooks_useWatch__WEBPACK_IMPORTED_MODULE_11__[key];
162
153
  }).bind(0, __WEBPACK_IMPORT_KEY__);
163
154
  __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
164
155
  })();
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "SunLxy <1011771396@qq.com>",
4
4
  "description": "表单组件公共hooks",
5
5
  "homepage": "https://github.com/SunLxy/carefrees-form-utils",
6
- "version": "0.0.5",
6
+ "version": "0.0.7",
7
7
  "main": "lib/index.js",
8
8
  "types": "lib/index.d.ts",
9
9
  "module": "esm/index.js",
@@ -21,7 +21,7 @@
21
21
  "esm"
22
22
  ],
23
23
  "dependencies": {
24
- "@carefrees/form-utils": "^0.0.5"
24
+ "@carefrees/form-utils": "^0.0.7"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/react": "18.2.21",
@@ -1,9 +1,8 @@
1
- import { useEffect, useRef } from 'react';
1
+ import { useEffect, useRef, useState } from 'react';
2
2
  import { RegisterFormItemOptions } from './register.FormItem';
3
3
  import { FormHideItemInstanceBase } from '@carefrees/form-utils';
4
4
  import { useFormItemParentName } from '../useFormItemParentName';
5
5
  import { useFormInstance } from '../useForm';
6
- import { useUpdate } from '../useUpdate';
7
6
 
8
7
  interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rules'> {}
9
8
 
@@ -11,13 +10,13 @@ interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rul
11
10
  export const useRegisterFormHideItem = (options: RegisterFormHideItemOptions) => {
12
11
  const { name, sort, isJoinParentField = true } = options;
13
12
  const form = useFormInstance();
14
- const _update = useUpdate();
13
+ const [, setValue] = useState({});
15
14
  const { newName, newSort } = useFormItemParentName({ name, sort, isJoinParentField });
16
15
  const hideItemInstance = useRef(new FormHideItemInstanceBase().ctor(newName)).current;
17
16
  const isHide = form.getFieldHideValue(newName);
18
-
17
+ hideItemInstance.preHideValue = isHide;
19
18
  hideItemInstance.instance = form;
20
- hideItemInstance.updated = _update.current;
19
+ hideItemInstance.updatedItem = setValue;
21
20
  hideItemInstance.sort = newSort;
22
21
 
23
22
  useEffect(() => {
@@ -2,10 +2,9 @@
2
2
  * @description 注册组件
3
3
  */
4
4
 
5
- import { useEffect, useMemo, useRef } from 'react';
5
+ import { useEffect, useMemo, useRef, useState } from 'react';
6
6
  import { RuleInstanceBase } from '@carefrees/form-utils';
7
7
  import type { RuleItem } from 'async-validator';
8
- import { useUpdate } from '../useUpdate';
9
8
  import { useFormInstance } from '../useForm';
10
9
  import { useFormItem } from '../useFormItem';
11
10
  import { useFormItemParentName } from '../useFormItemParentName';
@@ -26,6 +25,8 @@ export const useRegisterFormItem = (options: RegisterFormItemOptions) => {
26
25
  const { name, rules, sort, isJoinParentField = true } = options;
27
26
  const form = useFormInstance();
28
27
  const { newName, newSort, parentName } = useFormItemParentName({ name, sort, isJoinParentField });
28
+ const [, setValue] = useState({});
29
+
29
30
  // 注册规则
30
31
  // 注册单个实例
31
32
  const ruleInstance = useRef(new RuleInstanceBase()).current;
@@ -39,9 +40,8 @@ export const useRegisterFormItem = (options: RegisterFormItemOptions) => {
39
40
  formItemInstance.sort = newSort;
40
41
  formItemInstance.parentDataField = parentName;
41
42
 
42
- const _updated = useUpdate();
43
- formItemInstance.updated = _updated.current;
44
- ruleInstance.updated = _updated.current;
43
+ formItemInstance.updated = setValue;
44
+ ruleInstance.updated = setValue;
45
45
 
46
46
  useEffect(() => {
47
47
  const unMount = form.registerFormItem(formItemInstance);
package/src/index.ts CHANGED
@@ -9,5 +9,4 @@ export * from './hooks/useFormItemParentName';
9
9
  export * from './hooks/useFormList';
10
10
  export * from './hooks/useHtmlFor';
11
11
  export * from './hooks/useMultipleForm';
12
- export * from './hooks/useUpdate';
13
12
  export * from './hooks/useWatch';
@@ -1,2 +0,0 @@
1
- /**更新页面状态*/
2
- export declare const useUpdate: () => import("react").MutableRefObject<Function>;
@@ -1,10 +0,0 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
- const useUpdate = ()=>{
3
- const [, _update] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
4
- const refUpdate = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(()=>void 0);
5
- refUpdate.current = ()=>{
6
- _update({});
7
- };
8
- return refUpdate;
9
- };
10
- export { useUpdate };
@@ -1,2 +0,0 @@
1
- /**更新页面状态*/
2
- export declare const useUpdate: () => import("react").MutableRefObject<Function>;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- useUpdate: ()=>useUpdate
28
- });
29
- const external_react_namespaceObject = require("react");
30
- const useUpdate = ()=>{
31
- const [, _update] = (0, external_react_namespaceObject.useState)({});
32
- const refUpdate = (0, external_react_namespaceObject.useRef)(()=>void 0);
33
- refUpdate.current = ()=>{
34
- _update({});
35
- };
36
- return refUpdate;
37
- };
38
- exports.useUpdate = __webpack_exports__.useUpdate;
39
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
40
- "useUpdate"
41
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
42
- Object.defineProperty(exports, '__esModule', {
43
- value: true
44
- });
@@ -1,12 +0,0 @@
1
- import { useState, useRef } from 'react';
2
-
3
- /**更新页面状态*/
4
- export const useUpdate = () => {
5
- const [, _update] = useState({});
6
- /**为了防止 hooks 闭包问题*/
7
- const refUpdate = useRef<Function>(() => void 0);
8
- refUpdate.current = () => {
9
- _update({});
10
- };
11
- return refUpdate;
12
- };