Answer the question
In order to leave comments, you need to log in
What are the best practices for using React along with PHP templating engines (Blade, Twig)?
Hello!
I would like some sage advice on using React inside a regular PHP template engine.
The classic React usage model assumes that it fully implements the frontend, receiving and passing data to the server via the API. That is, by implementing an MVC application in PHP, I can completely hang all "V" and even partially "C" on React. But what if there is no need for this and I want to use the power of the PHP framework to implement the routing and output of HTML content, and I want to use react only to create reactivity in separate sections and blocks of the application? For example, a product catalog with filters and other interface elements. Is it enough to just create a div#catalog and render react components into it? If yes, then what is the best way to implement it? And what about SEO in this case?
I would be grateful for advice and links.
Answer the question
In order to leave comments, you need to log in
There is experience with Vue in a similar situation, the essence is the same.
Somewhere in the templates, a container for the component is formed, in the attributes of which the props for the component are passed:
<div
data-component="ComponentName"
data-component-props='{ "id": "123", "foo": "bar" }'
>
</div>
// псевдо-код
const el = получили элемент с data-component="ComponentName" или с каким-то id и т.д.
const props = спарсили пропсы из атрибута
const app = отрендерили React-компонент в этом жлементе передав ему пропсы
<div class="vue-widget">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question