mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-01 11:47:51 +08:00
fix: useEffect only on update
This commit is contained in:
parent
b0b79b7d9d
commit
f882ab42c5
@ -1,5 +1,5 @@
|
||||
import React, { useContext, useEffect, useMemo } from 'react';
|
||||
import { Schema, ISchemaFieldProps } from '@formily/react';
|
||||
import { ISchemaFieldProps, Schema } from '@formily/react';
|
||||
import React, { useContext, useEffect, useMemo, useRef } from 'react';
|
||||
import { SchemaComponentContext } from '../context';
|
||||
|
||||
function toSchema(schema?: any) {
|
||||
@ -21,11 +21,13 @@ export function SchemaComponent(props: ISchemaFieldProps) {
|
||||
const { schema: defaultSchema, ...others } = props;
|
||||
const { reset, SchemaField } = useContext(SchemaComponentContext);
|
||||
const schema = useMemo(() => toSchema(defaultSchema), []);
|
||||
// @ts-ignore
|
||||
// console.log('defaultSchema', JSON.stringify(schema.toJSON()));
|
||||
// TODO
|
||||
const isInitialMount = useRef(true);
|
||||
useEffect(() => {
|
||||
if (isInitialMount.current) {
|
||||
isInitialMount.current = false;
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
}, [JSON.stringify(defaultSchema)]);
|
||||
return <SchemaField {...others} schema={schema} />;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user