V
V
Vadim Stepanenko2019-11-28 22:35:46
PHP
Vadim Stepanenko, 2019-11-28 22:35:46

React + php, did I get the point right?

Hello everyone
. Let's say there is a php backend that accepts requests, processes, and sends data in json. For work I use XAMPP (i.e. site http://localhost)
Now we need to develop a SPA application for this backend. I came across react, got acquainted with some examples and docks, and a few (stupid) questions arose,
0. I know that react was originally developed for the node, but do I understand it correctly, it can also be used with php? If so, then in the examples everyone runs the application through npm, that is, through a node. What should I do? Run php via XAMPP + build react app on different port? Just include app.js as normal javascript on the html page, I guess is wrong? (warned, stupid questions :) )
1. Is the essence of react - to receive data from the server (json for example) and "build" the view on the client?
2. I used to use mvc on the php backend, where components were rendered in advance and given to the user. With recat, it doesn't make sense to render components on the server, right?
3. React is a JS framework, so the user can view the react code (meaning import lines, query lines, render lines)?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kafkae, 2019-11-28
@Kafkae

0. React doesn't care where the data comes from.
1. Yes.
2. Has if you need SSR. If you do not need it, then you do not need to draw anything on the back.
3. Yes.

D
Dmitry, 2019-11-28
@dimoff66

For 0-2 above, they answered
3. No, the user can look at the minified file and most likely understand no more from it than you understand by opening the .exe file in a text editor.

B
BATPYIIIKOB, 2019-11-29
@BATPYIIIKOB

0. React was originally developed as a view. Further overgrown with Flux and Redux .. Now the hooks ... It is advisable to use on projects above average. It turns out rather big bundle.js. On small projects, it is quite possible to get by with JS + libraries. Those. REACT is not JQuery, you need to build the final file with all the consequences.
1. Generally true.
2. At the output of the react - bundle.js is quite large. Generated via webpack (babel, etc.) Plus a bunch of small libraries
3. React itself is a library (A JavaScript library for building user interfaces), with its own rules and concept. Using pure react is hard, you need to understand the concept of props and states, virtual DOM.
Next, you still need to use Redux (state container) (well, or something like that). Debugging code with Redux-devtools.
In general, React teaches you to write good code for the work of a group of programmers or on an above-average project. There is a lot of code :) , but it is easy to maintain, and everything is on the shelves.
React is more about the view building approach.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question