简体   繁体   中英

Integrate a React Modal in a non-react website

So I'm trying to build a modal in react and integrate it into a non-react website. I understand that I might need to export the app as a UMD and include it as an embed script into the host website.

But how do I interact with the modal within the host website ie open a modal when a button is clicked and close the modal when a button is clicked within the modal.

Solution

It's unclear what you're trying to do, have react in just some place in an existing website ? You could just render you react app into a div and have it live there.

const element = <h1>Hello, world</h1>;
ReactDOM.render(element, document.getElementById('root'));

Even though if you plan on doing it this way, vue might be better suited.

Alternative

  • React would be a bit overkill for such a use case, where vue is suited perfectly for it.
  • Otherwise, I'd advise switching the whole web app to react. Depending on what technology it is made with currently, it might not be too difficult!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM