Skip to content

Commit

Permalink
Add signal to update the object reference when the primary key has ch…
Browse files Browse the repository at this point in the history
…anged.
  • Loading branch information
takameyer committed Aug 22, 2023
1 parent d967fbc commit 345c334
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ describe("useObject: rendering objects with a Realm.List property", () => {
// Render the old id
rerender(<App targetPrimaryKey={secondListId} />);

await waitFor(() => getByTestId(`listTitle${secondListId.toHexString()}`));
titleElement = getByTestId(`listTitle${secondListId.toHexString()}`);
expect(titleElement).toHaveTextContent("Second List");
});
Expand Down
5 changes: 4 additions & 1 deletion packages/realm-react/src/useObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down

0 comments on commit 345c334

Please sign in to comment.