@@ -294,11 +294,8 @@ PostMount Hook
294294
295295 The ``PostMount `` hook was added in TwigComponents 2.1.
296296
297- When a component is mounted with the passed data, if an item cannot be
298- mounted on the component, an exception is thrown. You can intercept this
299- behavior and "catch" this extra data with a ``PostMount `` hook method. This
300- method accepts the extra data as an argument and must return an array. If
301- the returned array is empty, the exception will be avoided::
297+ After a component is instantiated and its data mounted, you can run extra
298+ code via the ``PostMount `` hook::
302299
303300 // src/Components/Alert.php
304301 use Symfony\UX\TwigComponent\Attribute\PostMount;
@@ -319,18 +316,8 @@ the returned array is empty, the exception will be avoided::
319316
320317A ``PostMount `` method can also receive an array ``$data `` argument, which
321318will contain any props passed to the component that have *not * yet been processed,
322- i.e. because they don't correspond to any property. You can handle and remove those
323- here. For example, imagine an extra ``autoChooseType `` prop were passed when
324- creating the ``Alert `` component:
325-
326- .. code-block :: twig
327-
328- {{ component('Alert', {
329- message: 'Danger Will Robinson!',
330- autoChooseType: true,
331- }) }}
332-
333- You can handle this prop via a ``#[PostMount] `` hook::
319+ i.e. because they don't correspond to any property. You can handle these props,
320+ remove them from the ``$data `` and return the array::
334321
335322 // src/Components/Alert.php
336323 #[AsTwigComponent]
@@ -342,7 +329,7 @@ You can handle this prop via a ``#[PostMount]`` hook::
342329 #[PostMount]
343330 public function processAutoChooseType(array $data): array
344331 {
345- if (array_key_exists('autoChooseType', $data) && $data ['autoChooseType']) {
332+ if ($data['autoChooseType'] ?? false ) {
346333 if (str_contains($this->message, 'danger')) {
347334 $this->type = 'danger';
348335 }
0 commit comments