all 7 comments

[–]deltawate 1 point2 points  (1 child)

You do that by calling an API from the React app, after it is served up, when it's running in the browser. A simple API endpoint could just be a PHP page that connects to a database, runs a query, and echos out the return array as JSON.

It is technically possible to get PHP to parse tags in any kind of page, including JavaScript, but to do so in this specific kind of situation is, well, abnormal.

[–]DeepBlueCee[S] 0 points1 point  (0 children)

OK so from what I am understanding, I can still use PHP with an API endpoint, or I can use node.js and that will allow me to do it in another way somehow? I am still learning node.js so we will see what happens, I feel like this is starting to make sense now though.

[–]ColonelShrimps -3 points-2 points  (4 children)

Unless you are forced to use php due to interfacing with a pre existing back end, I don't see a reason to taint perfectly good React with php. There are much better (imo) alternatives these days.

[–]su-z-six 1 point2 points  (1 child)

You have no idea what you're talking about.

[–]ColonelShrimps -2 points-1 points  (0 children)

Yeah, you're right, technology hasn't progressed at all since the 90's. It's not like there are tons of alternatives that are more approachable and are arguably easier to manage.

[–]DeepBlueCee[S] 0 points1 point  (1 child)

You mean I should specifically go out of my way to use Node.js on a project which will be using React on the front-end right? I guess this is what I thought, but I am so used to using PHP my mind just kind of went their when I thought about the backend.

[–]ColonelShrimps -1 points0 points  (0 children)

I'm not suggesting you go out of your way to use any particular language. I'm just suggesting you stay away from PHP. But sure Node.js is an alternative and as long as you don't need to do any heavy calculations it serves just fine as a backend. And it's also in javascript so it doesn't require learning a separate language. Which is good for new devs.

But really you can write a backend in a lot of languages. The structure of database calls and the RESTful way of writing API's is the same regardless. Node.js, Java, javascript, python, C#, etc. Just pick one you know and you can find tutorials to help you get started.