[LiveComponent] Update doc for component initialization#3346
[LiveComponent] Update doc for component initialization#3346MrYamous wants to merge 2 commits intosymfony:2.xfrom
Conversation
src/LiveComponent/doc/index.rst
Outdated
| If you have a ``mount`` method declared in your component, it's required to | ||
| manually hydrate the prop:: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I see your point, i'll rewrite to be more accurate
| 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 | ||
| } |
There was a problem hiding this comment.
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.
Update
LiveComponentdocumentation to address #2937