I am trying to implement a form solution from formstack into my React/Gatsby website. To do so, I need to use postscribe
to inject an external script. I've followed a couple other people and I have a working version locally with the following code:
import postscribe from postscribe
...
useEffect(() => {
if (advRef) {
if (window !== undefined) {
postscribe(
advRef.current,
"<script src=...myformurl...><\/script>",
)
}
}
}, [advRef])
...
<div id="adv" ref={advRef}></div>
However, this does not work in production and it throws a ReferenceError: window is not defined
error. I have run into this before and as you can see I tried the if window is defined block, but that doesn't seem to help.
I saw in another question here that this has to do with how postscribe
is imported. But I can't seem to get the solution here to work either.