How can javaScript library and css files load before reactjs component load.
I am converting dataTable Html template to react component but javaScript library and css files are isn't loaded with components.
How can I solved it. Can any one help me?
You can use these lines at your very first component like app.js which renders first ater index.js(for class based components)
componentDidMount () {
const script = document.createElement("script");
script.src = "https://use.typekit.net/foobar.js";
script.async = true;
document.body.appendChild(script);
}
And for functional components
useEffect(() => {
const script = document.createElement("script");
script.src = "https://use.typekit.net/foobar.js";
script.async = true;
document.body.appendChild(script);
}, []);
You can try to use import [ which js library you want to use ] and then put this syntax at the js file top like as you import react;
import $ from 'jquery';
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.