Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
smnandre committed Oct 20, 2024
1 parent 3c792f3 commit d05a762
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/React/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ Symfony UX React
================

Symfony UX React is a Symfony bundle integrating `React`_ in
Symfony applications. It is part of `the Symfony UX initiative`_.
Symfony applications. It is part of the `Symfony UX initiative`_.

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

You can see a live example of this integration on the `Symfony UX React demo`_.

Symfony UX React supports React 18+.

Installation
Expand Down Expand Up @@ -41,6 +43,9 @@ React components.
Usage
-----

Register components
~~~~~~~~~~~~~~~~~~~

The Flex recipe will have already added the ``registerReactControllerComponents()``
code to your ``assets/app.js`` file:

Expand All @@ -55,7 +60,11 @@ This will load all React components located in the ``assets/react/controllers``
directory. These are known as **React controller components**: top-level
components that are meant to be rendered from Twig.

You can render any React controller component in Twig using the ``react_component()``.
Render in Twig
~~~~~~~~~~~~~~

You can render any React controller component in your Twig templates, using the
``react_component()`` function.

For example:

Expand All @@ -82,6 +91,30 @@ For example:
<div {{ react_component('Admin/OtherComponent') }}></div>
{% endblock %}

Permanent components
~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 2.21

The ability to mark a component ``permanent`` was added in UX React 2.21.

The controller responsible to render the React components can be configured
to keep the React component mounted when the root element is removed from
the DOM, using the ``permanent`` option.

This is particularly useful when the root element of a component is moved around
in the DOM or is removed and immediately re-added to the DOM (e.g. when using
`Turbo`_ and its `data-turbo-permanent` attribute).

.. code-block:: html+twig

{# templates/home.html.twig #}

Check failure on line 111 in src/React/doc/index.rst

View workflow job for this annotation

GitHub Actions / DOCtor-RST

Please remove blank line after "{# templates/home.html.twig #}"

{# The React component will stay mounted if the div is moved in the DOM #}
<div {{ react_component('Hello', {fullName: 'Fabien'}, {permanent: true}) }}>
Loading...
</div>

.. _using-with-asset-mapper:

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

.. _`React`: https://reactjs.org/
.. _`the Symfony UX initiative`: https://ux.symfony.com/
.. _`Symfony UX initiative`: https://ux.symfony.com/
.. _`Symfony UX React demo`: https://ux.symfony.com/react
:: _`Turbo`: https://turbo.hotwire.dev/

0 comments on commit d05a762

Please sign in to comment.