How to embed a p5.js sketch in a React page

Full demo code

Making p5.js sketches is incredibly fun and is an amazing tool for creative coding. However, while p5.js themselves show how to embed a sketch in pure html, it’s not clear how to embed one in a React app since the <script> tag doesn’t work the same way in a React component. Here’s how I figured out to do it:

Make a p5.js sketch