Skip to content

Comments

[LiveComponent] Update doc for component initialization#3346

Open
MrYamous wants to merge 2 commits intosymfony:2.xfrom
MrYamous:2937
Open

[LiveComponent] Update doc for component initialization#3346
MrYamous wants to merge 2 commits intosymfony:2.xfrom
MrYamous:2937

Conversation

@MrYamous
Copy link
Contributor

Q A
Bug fix? no
New feature? no
Deprecations? no
Documentation? yes
Issues Fix #2937
License MIT

Update LiveComponent documentation to address #2937

@carsonbot carsonbot added Documentation Improvements or additions to documentation LiveComponent Status: Needs Review Needs to be reviewed labels Feb 18, 2026
Comment on lines 530 to 531
If you have a ``mount`` method declared in your component, it's required to
manually hydrate the prop::
Copy link
Contributor

@norkunas norkunas Feb 19, 2026

Choose a reason for hiding this comment

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

While written like this, I'd understood that if you have mount method, then you need to set all properties manually, which is not the case - if you don't list them in mount, they are mounted automatically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point, i'll rewrite to be more accurate

Comment on lines +530 to +537
If you're using entities as ``LiveProp`` and having a ``mount`` method declared in
your component, it's required to manually hydrate the corresponding prop::

public function mount(Post $post)
{
$this->post = $post;
// .. doing something
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it's still not right, or else I didn't understand the issue... 😅

It is not related to \Symfony\UX\TwigComponent\ComponentFactory::mount(), that removes from $data, the properties defined in mount() arguments, requiring you to manually assign the property?

Given this example

#[AsTwigComponent]
class MyComponent {
    public string $foo;
    public string $bar;

    public function mount(string $foo, string $bar) {
        $this->foo = $foo;
        // missing $this->bar = $bar;
    }
}

Calling <twig:MyComponent foo="foo" bar="bar" /> will only set foo property if I'm not wrong.

To me, it is not related to LiveComponent at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation LiveComponent Status: Needs Review Needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initializing a component with a "Post"

4 participants