简体   繁体   中英

create react embeddable widget from create-react-app

I built a small react application using the create-react-app build configuration. The idea is that this app will be used like a widget which takes one parameter, an id of an element that will be used as a container for the app, so it can be embedded into any html page. Has anyone successfully done this? thanks,

this is similar to this this question

Should be possible. You would just have to figure out a way to initiate react to render within the parent application. You could do this by building your React, then in the parent application point to it so it gets loaded when you wanted it to.

You would also need a way to pass the data from the parent application to the react application more than likely using client side storage of some sort. (sessionStorage, localStorage, window, etc.)

You could have a config javascript object on the page where you load the react app.

window.config = {

"name":"dani";

}

Then inside the app read window.config and get your values.

You could also use LocalStorage.

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