From 345c334e7a9add586ce19ff52a6b47997378f02b Mon Sep 17 00:00:00 2001 From: Andrew Meyer Date: Tue, 22 Aug 2023 14:22:01 +0200 Subject: [PATCH] Add signal to update the object reference when the primary key has changed. --- packages/realm-react/src/__tests__/useObjectRender.test.tsx | 1 + packages/realm-react/src/useObject.tsx | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/realm-react/src/__tests__/useObjectRender.test.tsx b/packages/realm-react/src/__tests__/useObjectRender.test.tsx index b29aa153e1..fc138fcc07 100644 --- a/packages/realm-react/src/__tests__/useObjectRender.test.tsx +++ b/packages/realm-react/src/__tests__/useObjectRender.test.tsx @@ -417,6 +417,7 @@ describe("useObject: rendering objects with a Realm.List property", () => { // Render the old id rerender(); + await waitFor(() => getByTestId(`listTitle${secondListId.toHexString()}`)); titleElement = getByTestId(`listTitle${secondListId.toHexString()}`); expect(titleElement).toHaveTextContent("Second List"); }); diff --git a/packages/realm-react/src/useObject.tsx b/packages/realm-react/src/useObject.tsx index 1d3d28c064..985de52352 100644 --- a/packages/realm-react/src/useObject.tsx +++ b/packages/realm-react/src/useObject.tsx @@ -90,8 +90,11 @@ export function createUseObject(useRealm: () => Realm) { updatedRef, }); originalObjectRef.current = originalObject; - // Update the primaryKeyRef, so we can check if the primaryKey has changed on the next render + + // Primary key has updated, so update the reference primaryKeyRef.current = primaryKey; + // Signal that the object reference needs to be updated + updatedRef.current = true; } return cachedObjectRef.current; },