I haven’t used a build directly in a React component. What I usually do in my React projects is by using an iframe. Check this post, it contains sample code as well:
Got it, though with an iframe you can host the PlayCanvas build in your project. Download and export the build to a subfolder of your React project, and set a local relative url to the iframe.
Does that mean the playcanvas subfolder would need to be running in its own webserver as in the tutorial? I’m confused in how to incorporate it as part of the project, and run it when I run the react project.
Also are there any performance considerations with your approach? One reason why I’m shying away from iframes is that the games will be multiplayer, hence the iframe won’t be serving only static content.
Well, the same webserver that will execute your base React index.html can also run the PlayCanvas build files.
I’d say if you are using React for the UI of your game and you will not be exchanging significant amounts of data between React <-> PlayCanvas per frame, there won’t be any performance consideration at all.
If you are still concerned you can use PlayCanvas directly in a React Component. It won’t be easy since you will have to replicate the code that is found in the __start__.js file when exporting a PlayCanvas build. That is the PlayCanvas loader that boots the pc.Application instance.