-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Description
Hey folks. There is some slight issue with the example provided in the documentation:
window.addEventListener('message', (event) => {
if (event.data.type === 'devvit-message') {
const { message } = event.data;
console.log('Received from Devvit:', message);
}
});
https://developers.reddit.com/docs/webviews#from-devvit-to-web-view
When we send data from Devvit to the webview, it's structured differently, so trying to destructure the event.data
here is invalid.
type DevvitMessage = {
type: 'devvit-message';
data: {
message: {
// actual contents of whatever data I send from devvit backend
}
}
}
// the destructuring in the example from the docs does not work
// because there is no message key/prop inside event.data
// instead, the data is in event.data.data.message
// and the top level message has a "devvit-message" type hard-coded
Metadata
Metadata
Assignees
Labels
No labels