如何导入URL以与useEffect反应

时间:2020-07-20 09:29:23

标签: reactjs use-effect

该如何反应?导入URL以与useEffect反应。我做对了吗?

HTML

    // <style type="text/css" media="screen, projection">
    //     @import url(https://s3.amazonaws.com/assets.freshdesk.com/widget/freshwidget.css); 
    // </style> 

反应

useEffect(() => {
    const script = document.createElement('script');
  
    script.src = "https://s3.amazonaws.com/assets.freshdesk.com/widget/freshwidget.csss";
    script.type = "text/css";
    script.media = "screen, projection"
    script.async = true;
  
    document.body.appendChild(script);
  
    return () => {
      document.body.removeChild(script);
    }

}, []);

0 个答案:

没有答案