You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I previously would put this in _document.js, but this is no longer available. I have tried layout.tsx but it is not registering the script even though I see it in the head.
Any help is much appreciated <3
The text was updated successfully, but these errors were encountered:
Does anyone know how to get this external script (or any for that matter) on each page render? I get the nature of these applications are that they run once upon load (or refresh), but I need it to run with each page change.
You probably don't want to re-initialise the script on page change, but just call a certain function to trigger an action on page change. The documentation from the third-party script provider should contain that information.
If you really want to load and re-load on page change, you could write a component that looks like this and insert it in the root layour:
exportdefaultfunctionTestScript(){constpathname=usePathname()useEffect(()=>{constscript=document.createElement('script')script.src='https://connect.facebook.net/en_US/sdk.js'script.async=truescript.onload=()=>console.log('Script loaded correctly, window.FB has been populated')document.body.appendChild(script)return()=>{document.body.removeChild(script)}},[pathname])returnnull}
Hi there,
I am trying to put a script into my blog:
I previously would put this in
_document.js
, but this is no longer available. I have triedlayout.tsx
but it is not registering the script even though I see it in the head.Any help is much appreciated <3
The text was updated successfully, but these errors were encountered: