Skip to content

Commit a7e8ae5

Browse files
hedocodeweaverryan
authored andcommitted
React components : working twig example
1 parent 69925de commit a7e8ae5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/React/doc/index.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Finally, to load your React components, add the following lines to ``assets/app.
6262
// they are not necessary.
6363
registerReactControllerComponents(require.context('./react/controllers', true, /\.(j|t)sx?$/));
6464
65-
That's it! Create an `assets/react/controllers/` directory and start creating your
65+
That's it! Create an ``assets/react/controllers/`` directory and start creating your
6666
React components.
6767

6868
Usage
@@ -77,6 +77,7 @@ React components located in the directory ``assets/react/controllers`` are regis
7777
React controller components.
7878

7979
You can then render any React controller component in Twig using the ``react_component``.
80+
8081
For example:
8182

8283
.. code-block:: javascript
@@ -88,11 +89,19 @@ For example:
8889
return <div>Hello {props.fullName}</div>;
8990
}
9091
91-
9292
.. code-block:: html+twig
9393

9494
{# templates/home.html.twig #}
95-
<div {{ react_component('MyComponent', { 'fullName': app.user.fullName }) }}></div>
95+
{% extends 'base.html.twig' %}
96+
97+
{% block body %}
98+
<div {{ react_component('MyComponent', { 'fullName': number }) }}>
99+
Loading... <i class="fas fa-cog fa-spin fa-3x"></i>
100+
</div>
101+
102+
{# Component living in a subdirectory: "assets/react/controllers/Admin/OtherComponent" #}
103+
<div {{ react_component('Admin/OtherComponent') }}></div>
104+
{% endblock %}
96105

97106
Backward Compatibility promise
98107
------------------------------

0 commit comments

Comments
 (0)