Skip to content

Commit bcae0c4

Browse files
committed
minor #2431 Update [Live] Docs for PostHydrate, PreDehydrate & PreReRender (nehalgajjar)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Update [Live] Docs for PostHydrate, PreDehydrate & PreReRender | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Issues | Fix #2363 | License | MIT Update [Live] Docs for `PostHydrate`, `PreDehydrate` & `PreReRender` Commits ------- 1dfbc41 Update [Live] Docs for PostHydrate, PreDehydrate & PreReRender
2 parents e5fbfec + 1dfbc41 commit bcae0c4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,51 @@ let's keep going because… things get cooler.
181181
Need to do some extra data initialization on your component? Create
182182
a ``mount()`` method or use the ``PostMount`` hook: `Twig Component mount documentation`_.
183183

184+
Hooks: Handle Component Behavior
185+
--------------------------------
186+
Most of the time, you'll just pass data to your components and
187+
let it handle the rest. However, if you need to do something
188+
more complex during certain stages of a component's lifecycle, you
189+
can take advantage of lifecycle hooks.
190+
191+
``PostHydrate`` Hook
192+
~~~~~~~~~~~~~~~~~~~~
193+
The ``#[PostHydrate]`` hook is called immediately after the component's state
194+
is loaded from the client. This is useful if you need to process or adjust
195+
the data once it’s been hydrated.
196+
197+
``PreDehydrate`` Hook
198+
~~~~~~~~~~~~~~~~~~~~~
199+
The ``#[PreDehydrate]`` hook is triggered just before your component’s state
200+
is sent back to the client. You can use this to modify or clean up the data
201+
before it’s serialized and returned to the client.
202+
203+
``PreReRender`` Hook
204+
~~~~~~~~~~~~~~~~~~~~
205+
The ``#[PreReRender]`` hook is called before your component is re-rendered
206+
during an HTTP request. It does not run during the initial render but is
207+
helpful when you need to adjust the state before sending it back to
208+
the client for re-rendering.
209+
210+
Hook Priority
211+
~~~~~~~~~~~~~
212+
You can control the order in which hooks are executed by using the ``priority``
213+
argument. If multiple hooks of the same type are registered in a component, those
214+
with a higher priority value will run first. This allows you to manage the order
215+
in which your actions are performed within the same lifecycle stage::
216+
217+
#[PostHydrate(priority: 10)]
218+
public function highPriorityHook(): void
219+
{
220+
// Runs first
221+
}
222+
223+
#[PostHydrate(priority: 1)]
224+
public function lowPriorityHook(): void
225+
{
226+
// Runs last
227+
}
228+
184229
LiveProps: Stateful Component Properties
185230
----------------------------------------
186231

0 commit comments

Comments
 (0)