Search code examples
javascripthtmlreactjsdrag-and-droprender

How to convert React drag and drop page builder state to working html/css/js page


Recently, I am working to build a drag and drop UI builder for react based app frameworks. Before implementing drag and drop functionality, I am trying to render a page layout according to structured array stored in my state.

enter image description here

My question is, How can I render actual components with events such as OnClick, OnChange. Since I'm using "ReactDOMServer.renderToStaticMarkup" to convert the component to html/css, events are not triggering. Can someone provide me a way forward from here. I have added a sample code here. My plan is to use next js and SSR to render the page. Since converting the component to html/css, my event triggers are not triggering, I'm stuck here. I would love to see an example if someone can provide.

Sample - https://codesandbox.io/s/zeus-research-b61lwo?file=/src/Component.js:356-391


Solution

  • I'm answering my own question if someone thinking of following the same way of mine. I made a mistake by converting the react component to html/css and use dangerouslySetInnerHTML to render it. Instead of that, I'm going to render react component it self. So far, It is working. Ill update the answer if I get any issues.