@hzab/form-render 1.5.0 → 1.5.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/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/index.tsx +11 -10
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/index.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useEffect, useMemo, useImperativeHandle, forwardRef, useCallback } from "react";
|
1
|
+
import React, { useEffect, useMemo, useImperativeHandle, forwardRef, useCallback, useRef } from "react";
|
2
2
|
import { createForm } from "@formily/core";
|
3
3
|
import { createSchemaField } from "@formily/react";
|
4
4
|
import {
|
@@ -67,15 +67,16 @@ const antdComponents = {
|
|
67
67
|
ArrayCards,
|
68
68
|
};
|
69
69
|
|
70
|
-
/** schema scope 解决父级无 schema Scope 导致 scope 对象刷新的问题 */
|
71
|
-
let _schemaScope = { _$tempData: {} };
|
72
|
-
|
73
70
|
const FormRender = forwardRef((props: any, parentRef) => {
|
74
|
-
|
75
|
-
|
71
|
+
/** schema scope 解决父级无 schema Scope 导致 scope 对象刷新的问题 */
|
72
|
+
const schemaScopeRef = useRef<{ _$tempData: Object }>();
|
73
|
+
if (props.schemaScope && !schemaScopeRef.current) {
|
74
|
+
schemaScopeRef.current = props.schemaScope;
|
75
|
+
} else if (!schemaScopeRef.current) {
|
76
|
+
schemaScopeRef.current = { _$tempData: {} };
|
76
77
|
}
|
77
|
-
if (!
|
78
|
-
|
78
|
+
if (!schemaScopeRef.current?._$tempData) {
|
79
|
+
schemaScopeRef.current._$tempData = {};
|
79
80
|
}
|
80
81
|
const SchemaField = useCallback(
|
81
82
|
createSchemaField({
|
@@ -111,7 +112,7 @@ const FormRender = forwardRef((props: any, parentRef) => {
|
|
111
112
|
...customComponents,
|
112
113
|
...props.components,
|
113
114
|
},
|
114
|
-
scope:
|
115
|
+
scope: schemaScopeRef.current,
|
115
116
|
}),
|
116
117
|
[],
|
117
118
|
);
|
@@ -159,7 +160,7 @@ const FormRender = forwardRef((props: any, parentRef) => {
|
|
159
160
|
|
160
161
|
const schema = useMemo(() => {
|
161
162
|
return bindOnChange(props.schema, {
|
162
|
-
schemaScope:
|
163
|
+
schemaScope: schemaScopeRef.current,
|
163
164
|
onChange: props.onChange,
|
164
165
|
formRender,
|
165
166
|
});
|