In builder.io CMS I have a page with a custom code block and a embed media block, because I want to embed a miro.com whiteboard in my page.
If I hardcode the url in either of the blocks it works fine. As soon as I want to set the URL via state.miro_url it doesn’t.
For some reason I cannot get the state.miro_url to propagate and be properly rendered.
I have this nextjs code for the miro url:
use client
import { BuilderComponent } from '@builder.io/react';
import React, {useEffect, useRef} from 'react';
import { v4 as uuid } from 'uuid';
import { sseStore } from './SSEstore';
import { observer } from "mobx-react";
import { autorun } from "mobx";
const Context = observer(() => {
const miro_url = useRef(null);
...
useEffect(() => {
const disposer = autorun(() => {
if (sseStore.miro_url) {
miro_url.current = sseStore.miro_url;
console.log("miro_url.current: " + miro_url.current)
}
const storedValue = localStorage.getItem('miro_url');
if (storedValue) {
miro_url.current = storedValue;
console.log("miro_url.current reset from localStorage:" + miro_url.current)
}
});
return () => {
disposer();
};
});
...
return (
<BuilderComponent
model='page'
context={{
handleWebSocket: handleWebSocket,
handleAudioContext: handleAudioContext,
startSession: startUserSession,
}}
data={{
miro_url: miro_url.current
}}
/>
);
});
export default Context;
I Builder.io CMS I get the url via state.miro_url globally and connect it to the embed media block via Element Data Bindings. For the custom code block I tried injecting the url the same way, did not work. Any ideas?
I have tried hardcoding the url. This works. I have looked in the nginx error logs, nothing there. I have tried various builder.io cms blocks to create the iframe, all with the same result. I have seen it one single time working in my browser on the live site, which indicates to me, that something is wrong with the dynamic rendering of the miro_url parameter. The miro_url is stored in localStorage and sse storage properly, no problems there and rendering the miro board on my page also works when hardcoding the miro_url.
flodev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.