Skip to content

Commit

Permalink
Omit _key entirely if it is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
djohalo2 committed Mar 29, 2024
1 parent 50c8d7d commit 91ba1de
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/PageTreeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ export const PageTreeInput = (
};

const selectParentPage = (page: PageTreeItem) => {
// In the case of an array of references, we need to find the last path in the array and extract the _key
const lastPath = props.path[props.path.length - 1];
const _key = typeof lastPath === 'object' && '_key' in lastPath ? lastPath._key : undefined;

props.onChange(
set({
_key: _key,
...(_key ? { _key } : {}),
_ref: page._id,
_type: 'reference',
_weak: page.isDraft,
Expand Down

0 comments on commit 91ba1de

Please sign in to comment.