Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

script tag inside react component

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;
Comment

script tags in react

componentDidMount () {
    const script = document.createElement("script");

    script.src = "https://use.typekit.net/foobar.js";
    script.async = true;

    document.body.appendChild(script);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: hexstring to rgb array js 
Javascript :: how to send axios delete to the backend reactjs 
Javascript :: javascript sum of arguments 
Javascript :: jsonwebtoken error with react js 
Javascript :: http request javascript 
Javascript :: dropdown validation using jquery 
Javascript :: get ip address javascript 
Javascript :: get specific parent element jquery 
Javascript :: js fetch api 
Javascript :: add eslint dependencies for cypress 
Javascript :: Find the stray number 
Javascript :: how to append data to a field in mongoose model 
Javascript :: BREAK A LINE on JS 
Javascript :: js get node index 
Javascript :: hide column in antd table using js / react with conditional rendering 
Javascript :: map array method create object 
Javascript :: reverse array javascript 
Javascript :: remove duplicate value from string 
Javascript :: editting collection in firebase firestore 
Javascript :: javascript detect tab leave 
Javascript :: hard refresh javascript 
Javascript :: jquery show hide based on data attribute 
Javascript :: javascript debounce 
Javascript :: photo in React native 
Javascript :: mongodb limit find node 
Javascript :: visual studio code create react component shortcut 
Javascript :: using bootstrap with react 
Javascript :: dropzone csrf codeigniter 
Javascript :: sequelize migration set unique constraint 
Javascript :: yaml to json javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =