简体   繁体   English

从create-react-app创建react可嵌入的小部件

[英]create react embeddable widget from create-react-app

I built a small react application using the create-react-app build configuration. 我使用create-react-app构建配置构建了一个小型react应用程序。 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. 想法是,此应用程序的使用方式类似于带有一个参数的小部件,该参数是将用作应用程序容器的元素的id,因此可以将其嵌入到任何html页面中。 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. 您可以通过构建React来实现,然后在父应用程序中指向它,以便在需要时加载它。

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. 与使用某种客户端存储相比,您还需要一种将数据从父应用程序传递到React应用程序的方法。 (sessionStorage, localStorage, window, etc.) (sessionStorage,localStorage,window等)

You could have a config javascript object on the page where you load the react app. 您可以在加载React应用的页面上有一个配置javascript对象。

window.config = { window.config = {

"name":"dani"; “名”:“达尼”;

} }

Then inside the app read window.config and get your values. 然后在应用程序内部读取window.config并获取您的值。

You could also use LocalStorage. 您也可以使用LocalStorage。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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