fix: performance optimizations
This commit is contained in:
parent
c4816c6963
commit
c89d7f980f
@ -28,18 +28,20 @@ export const AssociationFieldProvider = observer(
|
|||||||
[fieldSchema['x-component-props']?.mode],
|
[fieldSchema['x-component-props']?.mode],
|
||||||
);
|
);
|
||||||
|
|
||||||
const targetKeyValue = useMemo(() => {
|
// const targetKeyValue = useMemo(() => {
|
||||||
if (!field.value) return '';
|
// if (!field.value) return '';
|
||||||
if (['belongsTo', 'hasOne'].includes(collectionField.type)) {
|
// if (['belongsTo', 'hasOne'].includes(collectionField.type)) {
|
||||||
return field.value[collectionField.targetKey] ?? '';
|
// return field.value[collectionField.targetKey] ?? '';
|
||||||
}
|
// }
|
||||||
if (['belongsToMany', 'hasMany'].includes(collectionField.type)) {
|
// if (['belongsToMany', 'hasMany'].includes(collectionField.type)) {
|
||||||
if (Array.isArray(field.value)) {
|
// if (Array.isArray(field.value)) {
|
||||||
return field.value.map((v) => v[collectionField.targetKey] ?? '').join(',');
|
// return field.value.map((v) => v[collectionField.targetKey] ?? '').join(',');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return '';
|
// return '';
|
||||||
}, [collectionField, field.value]);
|
// }, [collectionField, field.value]);
|
||||||
|
|
||||||
|
const fieldValue = useMemo(() => JSON.stringify(field.value), [field.value]);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ export const AssociationFieldProvider = observer(
|
|||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [currentMode, collectionField, targetKeyValue]);
|
}, [currentMode, collectionField, fieldValue]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user