📜  react中如何通过脚本导入js - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:59.385000             🧑  作者: Mango

代码示例2
import { useEffect } from 'react';

const useScript = url => {
  useEffect(() => {
    const script = document.createElement('script');

    script.src = url;
    script.async = true;

    document.body.appendChild(script);

    return () => {
      document.body.removeChild(script);
    }
  }, [url]);
};

export default useScript;