1

I am building a site using React + Gatsby and need to use Paper.js on the client side.

Currently I put the script into inside the render()


<Helmet>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.2/paper-full.min.js" />
</Helmet>

However it is working when i reload (f5) but not when the user is directed to the page clicking a Gatsby-Link element (to="/path")

What could be my problem?

1 Answers1

0

You can pass Helmet a script prop with an array of scripts to include:

<Helmet
  script={[
    {
      "src": "https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.2/paper-full.min.js", 
      "type": "text/javascript"
    }
  ]}
>
...
</Helmet>
Nick
  • 16,066
  • 3
  • 16
  • 32
  • Would I put the inside my JSX of the render() of the component? –  Oct 27 '19 at 20:39
  • Hmm I’m not sure if I’m following your issue fully, but perhaps onChangeClientState is what you’re looking for? https://github.com/nfl/react-helmet/issues/146#issuecomment-271552211 – Nick Oct 27 '19 at 20:43
  • 1
    For some reason passing the ```script``` prop solved my problem. If I find out why exactly I will add it here. Thanks alot! –  Oct 27 '19 at 20:50
  • Please do... because I don’t know either ;) – Nick Oct 27 '19 at 20:52