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; },