First off, I realize this is a very niche problem. I'm building an app for the Wix app market. It's a widget that runs in an iframe. Wix has a 'preview' mode that basically shows what the live site will look like if it's published. Wix has an API that lets you listen for events. One of these events is EDIT_MODE_CHANGE, which refers to switching between editor and preview. The issue I'm running into is that when I click preview, it unmounts the iframe and reloads the app, preventing it from listening for the event because essentially the app is no longer running, at least that is my understanding.
Here is my code that adds the event listener:
const [wixEditMode, setWixEditMode] = useState("editor");
const editModeChange = (e) => {
setWixEditMode(e.editMode);
console.log("editModeChange", e);
};
useEffect(() => {
Wix.addEventListener(Wix.Events.EDIT_MODE_CHANGE, editModeChange);
return () => {
Wix.removeEventListener(Wix.Events.EDIT_MODE_CHANGE, editModeChange);
};
}, []);
The event function never fires. So I have no way to persist the edit mode state through local storage or other means. I'm at a loss at what to do. Any help would be much appreciated. I opened a ticket with Wix as well. Thanks!