
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see the issue! The problem is in your preview.prepare() function. You're returning { id: 'id' } (the string "id") instead of { id: id } (the actual value). This means your TwitterPreview component is receiving the string literal "id" instead of the actual ID value, which is why you're getting the destructuring error.
Here's the corrected code:
preview: {
select: {
id: 'id'
},
prepare(selection) {
const { id } = selection;
return {
id: id // or just { id } using shorthand
};
}
}The prepare() function receives the data you selected (in this case, { id: 'actual-tweet-id' }), and whatever you return from prepare() gets passed as props to your custom preview component. By returning { id: 'id' }, you were literally passing the string "id" instead of the actual tweet ID value.
Even simpler approach: Since you're just passing through the selected value without transformation, you can actually omit the prepare() function entirely:
preview: {
select: {
id: 'id'
}
}When you only need select without any transformation, Sanity will automatically pass the selected values to your preview component as props.
Your TwitterPreview component looks good otherwise - it properly checks for the id and renders the embed. Once you fix the prepare() function, your custom embed should work perfectly, and you'll be able to follow the same pattern for other embeds (YouTube, Instagram, etc.) by just changing the field names and embed components.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store