@@ -181,6 +181,51 @@ let's keep going because… things get cooler.
181
181
Need to do some extra data initialization on your component? Create
182
182
a ``mount() `` method or use the ``PostMount `` hook: `Twig Component mount documentation `_.
183
183
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
+
184
229
LiveProps: Stateful Component Properties
185
230
----------------------------------------
186
231
0 commit comments