@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 CHANGED
@@ -1,3 +1,7 @@
1
+ # @hzab/form-render@1.5.1
2
+
3
+ fix: schemaScope 使用 Ref 缓存,解决 tempData 更新问题
4
+
1
5
  # @hzab/form-render@1.5.0
2
6
 
3
7
  feat: ossUpload 文件目录配置 dir 前缀 oss-upload 文件目录;dir 格式格式化
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/form-render",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
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
- if (props.schemaScope) {
75
- _schemaScope = props.schemaScope;
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 (!props.schemaScope?._$tempData) {
78
- _schemaScope._$tempData = {};
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: _schemaScope,
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: _schemaScope,
163
+ schemaScope: schemaScopeRef.current,
163
164
  onChange: props.onChange,
164
165
  formRender,
165
166
  });