window variable in fresh islands
How do I access
window
in islands? I need to modify DOM code client side.4 Replies
Check if it’s the browser with
IS_BROWSER
from $fresh/runtime.ts
inside an useEffect hook and you’re all setYou could have a look at ...
https://fresh-ssr-spa.deno.dev/
wow. this really helped. but I am stuck at similar other things. basically, I am trying to port this code in fresh. how do I import the
<script/>
tags?
https://github.com/microsoft/monaco-editor/blob/main/samples/browser-script-editor/index.html
I came this far,
This works fine. but I would prefer not to use the <script/>
and <link/>
tags. How do I do this cleanly in fresh?I’ve just come across that problem when doing another project. What I did was create an async function inside an
useEffect
, and import dynamically the module. After that normally a global variable is created, so you declare it at the top of the file
After await
ing the import you can use the variable inside the hook, inside the is browser if