Skip to content

React components : working twig example #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2023
Merged

React components : working twig example #778

merged 1 commit into from
Apr 16, 2023

Conversation

hedocode
Copy link
Contributor

@hedocode hedocode commented Apr 11, 2023

Hello ! The tutorial didn't work because I had not the following lines in my twig :

{% block stylesheets %}{{ encore_entry_link_tags('app') }}{% endblock %}
{% block javascripts %}{{ encore_entry_script_tags('app') }}{% endblock %}

Q A
Bug fix? yes
New feature? no
Tickets N/A
License MIT

.. code-block:: html+twig

{# templates/home.html.twig #}

{% block stylesheets %}{{ encore_entry_link_tags('app') }}{% endblock %}
{% block javascripts %}{{ encore_entry_script_tags('app') }}{% endblock %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. These ARE needed, but they're supposed to live in your base.html.twig file and they should already be there by default (when you install Twig, it ships with a base.html.twig that has these two lines). Did you not have these lines already in your base.html.twig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right !
Thank you for the precision, I didn't check the generated base.html.twig yet as the tutorial didn't extend it.

I added more informations so new users can make it work by copy-pasting, and still understand why it's needed with a link to related Encore documentation.

Sorry for the huge quantity of commits, I have been fighting with DOCtor RST, and he won by saying there is an error on a file I didn't change, on a line that does not have the problematic code :

src/LiveComponent/doc/index.rst ✘
581: Please use "html+twig" instead of "twig"

Have a good day !
Best regards

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's see. Hmm. Earlier, on line 16 (first line under installation), we say:

Before you start, make sure you have Symfony UX configured in your app_.

That is where, in theory, we're trying to point you to "make sure you have Encore fully installed and working in your app". By putting that note there, we don't need to include those details later on. Adding them here "muddies" the docs because these notes are really about setting up Encore/Symfony UX, and not about actually installing React.

Did you see that note on line 16? Is it too subtle? Could you suggest a change to it? I'd very much like to improve that as needed, and not include the new notes here (and, btw, absolutely no problem with many commits - keep going - we automatically squash when we merge).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're trying to point you to "make sure you have Encore fully installed and working in your app"

I noticed that after, that's a bit of "recursion" but with attentive read it's clear enough.

these notes are really about setting up Encore/Symfony UX, and not about actually installing React

I agree with you that this page's responsibility is about Symfony React UX and therefore don't need to remind every dependencies such as Encore on it. According to that, I removed the Encore note and just kept the modified example extending base.html.twig.

@hedocode hedocode changed the title Working twig example React components : working twig example Apr 12, 2023
@hedocode
Copy link
Contributor Author

Another thing, I noticed that they are no explanation for components in subfolders, I expected it to work by writing the component file name but we actually need to write the path to it from the root folder, can I document it in this pull request or may I create a new one for this ?

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing, I noticed that they are no explanation for components in subfolders, I expected it to work by writing the component file name but we actually need to write the path to it from the root folder, can I document it in this pull request or may I create a new one for this ?

Yea, this is something that should be mentioned - totally ok to include it here 👍

.. code-block:: html+twig

{# templates/home.html.twig #}

{% block stylesheets %}{{ encore_entry_link_tags('app') }}{% endblock %}
{% block javascripts %}{{ encore_entry_script_tags('app') }}{% endblock %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's see. Hmm. Earlier, on line 16 (first line under installation), we say:

Before you start, make sure you have Symfony UX configured in your app_.

That is where, in theory, we're trying to point you to "make sure you have Encore fully installed and working in your app". By putting that note there, we don't need to include those details later on. Adding them here "muddies" the docs because these notes are really about setting up Encore/Symfony UX, and not about actually installing React.

Did you see that note on line 16? Is it too subtle? Could you suggest a change to it? I'd very much like to improve that as needed, and not include the new notes here (and, btw, absolutely no problem with many commits - keep going - we automatically squash when we merge).

<div {{ react_component('MyComponent', { 'fullName': number }) }}>
Loading... <i class="fas fa-cog fa-spin fa-3x"></i>
</div>
{% endblock %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm totally fine with this change - it makes it more complete, without distracting too much

@hedocode
Copy link
Contributor Author

Yea, this is something that should be mentioned - totally ok to include it here +1

Done ! ✔️

@@ -77,6 +77,9 @@ React components located in the directory ``assets/react/controllers`` are regis
React controller components.

You can then render any React controller component in Twig using the ``react_component``.
The first parameter is the path to the component from the root context folder, without extension at the end.
The second is the component props object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about, instead of this note, we add a commented-out code example below - I'll suggest below

{% block body %}
<div {{ react_component('MyComponent', { 'fullName': number }) }}>
Loading... <i class="fas fa-cog fa-spin fa-3x"></i>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</div>
</div>
{# component living in a subdirectory: "assets/react/controllers/Admin/OtherComponent" #}
<div {{ react_component('Admin/OtherComponent') }}></div>

The name Admin/OtherComponent is correct here, right? 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct ! I just verified it :)

@weaverryan
Copy link
Member

Thank you @hedocode!

@weaverryan weaverryan merged commit a61e48b into symfony:2.x Apr 16, 2023
@hedocode
Copy link
Contributor Author

You're welcome !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants