Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

javascript - How to import a custom react component from the public folder and insert it in a react project that is already deployed

I have a react app that gets hosted internally for each of its users. Once the app is deployed in tomcat, I would like the user to be able to insert a javascript file in the public folder to return html and custom data fetched from an API into a typycal 'div" with an id inside of a side Panel, and therefore make the application customizable.

That way, the user would be able to develop their own javascrpit file to customize what they can see in the side panel

So, I understand it's possible to simply use the following method to import the javascript file this way:

var customSidePanel = require('../../../public/plugins/customSidePanel');

<PanelPaper title={'Custom Properties'}>
    <div id={"customSidePanel-div"}>
        {customSidePanel() != null && customSidePanel()}
    </div>
</PanelPaper>

and the very simple js file:

module.exports = function () {
    return 'Soon to be more';
}

The user would then be able to update their own custom side panel plugin without redeploying the entire app.

Is there a more efficient way of doing this? A way that would let me use react and other dependencies that I am alkready using in my existing react project? Is there a library that would allow me to do this? Should I make a completely new react project as a base for the user to use for their custom side panel?

question from:https://stackoverflow.com/questions/65944410/how-to-import-a-custom-react-component-from-the-public-folder-and-insert-it-in-a

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...