Skip to content

Commit d05a762

Browse files
committed
Update doc
1 parent 3c792f3 commit d05a762

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/React/doc/index.rst

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ Symfony UX React
22
================
33

44
Symfony 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

77
React is a JavaScript library for building user interfaces.
88
Symfony UX React provides tools to render React components from Twig,
99
handling rendering and data transfers.
1010

11+
You can see a live example of this integration on the `Symfony UX React demo`_.
12+
1113
Symfony UX React supports React 18+.
1214

1315
Installation
@@ -41,6 +43,9 @@ React components.
4143
Usage
4244
-----
4345

46+
Register components
47+
~~~~~~~~~~~~~~~~~~~
48+
4449
The Flex recipe will have already added the ``registerReactControllerComponents()``
4550
code to your ``assets/app.js`` file:
4651

@@ -55,7 +60,11 @@ This will load all React components located in the ``assets/react/controllers``
5560
directory. These are known as **React controller components**: top-level
5661
components 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

6069
For example:
6170

@@ -82,6 +91,30 @@ 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+
113+
{# The React component will stay mounted if the div is moved in the DOM #}
114+
<div {{ react_component('Hello', {fullName: 'Fabien'}, {permanent: true}) }}>
115+
Loading...
116+
</div>
117+
85118
.. _using-with-asset-mapper:
86119

87120
Using with AssetMapper
@@ -119,4 +152,6 @@ the Symfony framework:
119152
https://symfony.com/doc/current/contributing/code/bc.html
120153

121154
.. _`React`: https://reactjs.org/
122-
.. _`the Symfony UX initiative`: https://ux.symfony.com/
155+
.. _`Symfony UX initiative`: https://ux.symfony.com/
156+
.. _`Symfony UX React demo`: https://ux.symfony.com/react
157+
:: _`Turbo`: https://turbo.hotwire.dev/

0 commit comments

Comments
 (0)