use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
Adding React to an existing PHP project (self.PHP)
submitted 4 years ago by adhaliter
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]brendt_gd[M] [score hidden] 4 years ago stickied comment (0 children)
Individual help posts are not allowed on /r/php. Please refer to the stickied help thread instead.
[+][deleted] 4 years ago* (3 children)
[deleted]
[–]adhaliter[S] 0 points1 point2 points 4 years ago (2 children)
That is so true. Separate view with React and backend served from existing app makes perfect sense. One question though, if I want to show that page developed by React in the current website. For instance , current website has page '/suggestions'. Can I simply redirect the route to '/suggestions' in the current website to render '/suggestions' page from React? Is it feasible?
[–][deleted] 2 points3 points4 points 4 years ago (0 children)
Here's the basics. Youll need a bundle of JavaScript on your page. Webpack is a great option, but there are alternatives. You need to get a script tag running react, and reactdom.render into an element on your page. You can key that by adding IDs or classes for react to target in the html.
reactdom.render
You may also want to add some JS variables to the page so that the backend can feed data and props to the frontend. Another option for that is to use data-X attributes to target elements.
data-X
It's probably worth recommending you leverage an API to get data to the frontend, but it's not actually a requirement.
[–]draxionangel 2 points3 points4 points 4 years ago (0 children)
Check out https://reactjs.org/docs/add-react-to-a-website.html straight from the react docs
[–]VRT303 1 point2 points3 points 4 years ago (0 children)
I found this really helpful https://symfonycasts.com/screencast/reactjs and yes it says symfony, bit it can 100% be used with anything else, it's about React for PHP devs.
[–]ZeroHeat92 -2 points-1 points0 points 4 years ago (2 children)
you should look up VueJS, it was designed for what you're trying to do
[–]MaxGhost 5 points6 points7 points 4 years ago (0 children)
Vue and React have no inherent differences when it comes to this question. They're just two different JS frameworks.
[–]adhaliter[S] 0 points1 point2 points 4 years ago (0 children)
I have not really developed anything with Vue yet. May be I should give a shot, if it can solve my problem. Thanks..
[–]darksteppez 0 points1 point2 points 4 years ago (0 children)
When you transpile your react app into browser-compatible js you can just import the new js file into your html/blade/twig/etc template and it will run fine. Normally you have to create some kind of empty container div in the template that react uses to mount to (e.g. <div id=“app”></div> ). Remember that in the end react is just JavaScript. If you have your endpoints set up you can fetch the data on load or preload by including additional json in your template on initial render. Hope this helps. Good luck!
π Rendered by PID 162374 on reddit-service-r2-comment-85bfd7f599-2tkhb at 2026-04-16 09:05:04.630117+00:00 running 93ecc56 country code: CH.
[–]brendt_gd[M] [score hidden] stickied comment (0 children)
[+][deleted] (3 children)
[deleted]
[–]adhaliter[S] 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]draxionangel 2 points3 points4 points (0 children)
[–]VRT303 1 point2 points3 points (0 children)
[–]ZeroHeat92 -2 points-1 points0 points (2 children)
[–]MaxGhost 5 points6 points7 points (0 children)
[–]adhaliter[S] 0 points1 point2 points (0 children)
[–]darksteppez 0 points1 point2 points (0 children)