React <App/> in Drupal or WordPress

I’ve done some basic sites in Drupal and WordPress
I’m making my way through Create React App tutorials now.
What I’m curious about is best practice for displaying my peanut butter inside the chocolate… my first thought is an iframe… Create React App bootstraps the shell, but I could also add react scripts at the top of the page. So what I’m trying to figure out is should I just run npm build on the src and then move the build directory into the CMS after that? Are there any tutorials covering best practices for this process?

Yup. That’s normally how you deploy a React app (build it, then upload the compiled JS somewhere).

Don’t do that. It’s hacky.


In more general terms, I suppose the question I would ask is why do you want to do this? React is cool and all, but it’s not really suited to building a static site.

I’ve built complete sites in it… but I agree, it’s more for modular components. I’m working on a game in a chat app and wanted to place that module in a Drupal or WordPress site. And it wouldn’t be static, it’s using chat socket.io and will have to bounce off the server. If it was static I’d just put it on github.io
Should I use
npm run eject
as a part of this process?

Not really. All that does is move create-react-app’s configuration files and into you app directory. If you don’t have a need to modify the config or scripts you don’t need to eject.

React is cool and all, but it’s not really suited to building a static site.

I mean… that’s not really true. Gatsby and Next.js are great choices for static sites.

This just happened 3 days ago.

@TurtleWolf1 Headless might be what you’re looking for.

This is a good place to start.

If it was static

If you’re not server rendering, then it’s static. Bouncing off a web socket or hitting an API doesn’t make it not static.

I wasn’t really talking about site generators. What I meant that a library like React is best suited to a data-driven application, or an application that deals with a reasonable amount of state.

Of course there’s nothing stopping you writing a widget using React and dropping it into a regular page on your CMS (which is what it sounds like the OP is proposing), but I’m not sure how much benefit React gives you in that case.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.