@@ -2,12 +2,14 @@ Symfony UX React
22================
33
44Symfony UX React is a Symfony bundle integrating `React `_ in
5- Symfony applications. It is part of ` the Symfony UX initiative `_.
5+ Symfony applications. It is part of the ` Symfony UX initiative `_.
66
77React is a JavaScript library for building user interfaces.
88Symfony UX React provides tools to render React components from Twig,
99handling rendering and data transfers.
1010
11+ You can see a live example of this integration on the `Symfony UX React demo `_.
12+
1113Symfony UX React supports React 18+.
1214
1315Installation
@@ -41,6 +43,9 @@ React components.
4143Usage
4244-----
4345
46+ Register components
47+ ~~~~~~~~~~~~~~~~~~~
48+
4449The Flex recipe will have already added the ``registerReactControllerComponents() ``
4550code to your ``assets/app.js `` file:
4651
@@ -55,7 +60,11 @@ This will load all React components located in the ``assets/react/controllers``
5560directory. These are known as **React controller components **: top-level
5661components that are meant to be rendered from Twig.
5762
58- You can render any React controller component in Twig using the ``react_component() ``.
63+ Render in Twig
64+ ~~~~~~~~~~~~~~
65+
66+ You can render any React controller component in your Twig templates, using the
67+ ``react_component() `` function.
5968
6069For example:
6170
@@ -82,6 +91,31 @@ For example:
8291 <div {{ react_component('Admin/OtherComponent') }}></div>
8392 {% endblock %}
8493
94+ Permanent components
95+ ~~~~~~~~~~~~~~~~~~~~
96+
97+ .. versionadded :: 2.21
98+
99+ The ability to mark a component ``permanent `` was added in UX React 2.21.
100+
101+ The controller responsible to render the React components can be configured
102+ to keep the React component mounted when the root element is removed from
103+ the DOM, using the ``permanent `` option.
104+
105+ This is particularly useful when the root element of a component is moved around
106+ in the DOM or is removed and immediately re-added to the DOM (e.g. when using
107+ `Turbo `_ and its `data-turbo-permanent ` attribute).
108+
109+ .. code-block :: html+twig
110+
111+ {# templates/home.html.twig #}
112+ {% extends 'base.html.twig' %}
113+
114+ {# The React component will stay mounted if the div is moved in the DOM #}
115+ <div {{ react_component('Hello', {fullName: 'Fabien'}, {permanent: true}) }}>
116+ Loading...
117+ </div>
118+
85119.. _using-with-asset-mapper :
86120
87121Using with AssetMapper
@@ -119,4 +153,6 @@ the Symfony framework:
119153https://symfony.com/doc/current/contributing/code/bc.html
120154
121155.. _`React` : https://reactjs.org/
122- .. _`the Symfony UX initiative` : https://ux.symfony.com/
156+ .. _`Symfony UX initiative` : https://ux.symfony.com/
157+ .. _`Symfony UX React demo` : https://ux.symfony.com/react
158+ :: _`Turbo `: https://turbo.hotwire.dev/
0 commit comments