Add external URL using script tag in React js app
My requirement is to add the external website vi开发者_StackOverflow社区a script tag to my react js project.
I have already tried react-helmet
and react-script-tag
.
I have added using it custom function while inspecting the UI, I am able to view the script added into the head but still UI is not rendering.
This is my App.js
import React from 'react';
import './App.css';
export function AddLibrary(urlOfTheLibrary) {
const script = document.createElement('script');
script.src = urlOfTheLibrary;
script.async = true;
document.head.appendChild(script);
}
function App() {
return (
<div className="App">
{AddLibrary(
'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js')}
</div>
);
}
export default App;
It would be really great to get some help here.
Thanks in Advance.
If I got it right, you want to add a script tag so it is working immediately, for security reasons the browser will not allow run it.
精彩评论