Hi everyone,
I’m working on replicating Figma elements in a React frontend. The goal is to replicate the exact position, size, and style of the selected element in Figma, using the data sent by the Figma plugin.
What I’ve Done
- I’m receiving the data from the Figma then try to send it to frontend.
const selection = figma.currentPage.selection;
figma.ui.postMessage({ type: "selection-changed", selection});
- In frontend, try to render with that data.
useEffect(() => {
window.onmessage = (event) => {
const { type, selection} = event.data.pluginMessage;
if (type === "selection-changed" && selection) {
setElements(selection);
}
};
return () => {
window.onmessage = null;
};
}, []);
return (
<div className="work-board">
<div className="main-board">
<div className="drop-board">
{elements.length === 0 ? (
<p>Select a frame or two to get started</p>
) : (
elements.map((element) => renderVisualElement(element))
)}
</div>
...
But that is not rendering.
How can I fix this so that the selected Figma elements render exactly as they appear in Figma?