0

I am trying to create a widget which can be plugged to any website, just like some chat widget. I am trying to below but getting error:

const widgetDivs = document.querySelectorAll('.proc_widget');

   widgetDivs.forEach((div) => {
      ReactDOM.render(
        <React.StrictMode>
          <App symbol={div.dataset.symbol} />
        </React.StrictMode>,
        div
      );
    });


 ERROR:  Uncaught TypeError: react_dom_client__WEBPACK_IMPORTED_MODULE_1__.render is not a function

I was referring this: https://tekinico.medium.com/build-a-react-embeddable-widget-c46b7f7999d8

but looks like this is old post and I am using latest version of react, which directly render root. can someone please share me some idea to make a widget and bundle it.

Atul Verma
  • 361
  • 8
  • 22

2 Answers2

0

Please check my answer to the follwing question: Building a Live Chat Widget from Scratch using React

I'm pretty sure there is all you need to start buildind web widget.

Antek
  • 575
  • 3
  • 11
0

I fixed it by doing below:

const widgetDivs = document.querySelectorAll('.proc_widget');

widgetDivs.forEach((div) => {
  const root = ReactDOM.createRoot(div);
  root.render(
    <React.StrictMode>
      <App symbol={div.dataset.symbol} />
    </React.StrictMode>
  );
});
Atul Verma
  • 361
  • 8
  • 22