I have a relatively straightforward issue of trying to add inline scripting to a React component. What I have so far:
\'use strict\';
import \'../../styles/
According to Alex McMillan's solution, I have the following adaptation.
My own environment: React 16.8+, next v9+
// add a custom component named Script
// hooks/Script.js
import { useEffect } from 'react'
const useScript = (url, async) => {
useEffect(() => {
const script = document.createElement('script')
script.src = url
script.async = (typeof async === 'undefined' ? true : async )
document.body.appendChild(script)
return () => {
document.body.removeChild(script)
}
}, [url])
}
export default function Script({ src, async=true}) {
useScript(src, async)
return null // Return null is necessary for the moment.
}
// Use the custom compoennt, just import it and substitute the old lower case tag with the custom camel case tag would suffice.
// index.js
import Script from "../hooks/Script";
{/* Google Map */}
this.el = el} className="gmap">
{/* Old html script */}
{/**/}
{/* new custom Script component */}