Fix table re-renders on update field (#6722)

The update of all fields was caused by `useContextSelector` not being
properly implemented.

As it is a memoization library the `useRecordFieldValue` hook wasn't
giving to the library the required things to allow memoization.

I just added recordId + fieldName to the memoization function so that
`useContextSelector` doesn't recompute itself whenever any record
changes.
This commit is contained in:
Lucas Bordeau
2024-08-23 19:31:27 +02:00
committed by GitHub
parent e49acae851
commit 6467da5cab
4 changed files with 9 additions and 9 deletions

View File

@ -30,22 +30,22 @@ export const useSetRecordValue = () => {
export const useRecordValue = (recordId: string) => {
const tableValue = useContextSelector(
RecordFieldValueSelectorContext,
(value) => value[0],
(value) => value[0]?.[recordId],
);
return tableValue?.[recordId] as ObjectRecord | undefined;
return tableValue as ObjectRecord | undefined;
};
export const useRecordFieldValue = <T,>(
recordId: string,
fieldName: string,
) => {
const recordFieldValues = useContextSelector(
const recordFieldValue = useContextSelector(
RecordFieldValueSelectorContext,
(value) => value[0],
(value) => value[0]?.[recordId]?.[fieldName],
);
return recordFieldValues?.[recordId]?.[fieldName] as T;
return recordFieldValue as T | undefined;
};
export const useSetRecordFieldValue = () => {