• **after**: (`callback`: `A` extends `Record`\<`ActionName`, [`_Method`](../modules/pinia.md#_Method)\> ? (`resolvedReturn`: [`_Awaited`](../modules/pinia.md#_Awaited)\<`ReturnType`\<`A`[`ActionName`]\>\>) => `void` : () => `void`) => `void`
+Sets up a hook once the action is finished. It receives the return value
+of the action, if it's a Promise, it will be unwrapped.
+
#### Type declaration
▸ (`callback`): `void`
• **onError**: (`callback`: (`error`: `unknown`) => `void`) => `void`
+Sets up a hook if the action fails. Return `false` to catch the error and
+stop it from propagating.
+
#### Type declaration
▸ (`callback`): `void`
▸ (): `void`
-Setups a callback to be called every time an action is about to get
-invoked. The callback receives an object with all the relevant information
-of the invoked action:
-- `store`: the store it is invoked on
-- `name`: The name of the action
-- `args`: The parameters passed to the action
-
-On top of these, it receives two functions that allow setting up a callback
-once the action finishes or when it fails.
-
-It also returns a function to remove the callback. Note than when calling
-`store.$onAction()` inside of a component, it will be automatically cleaned
-up when the component gets unmounted unless `detached` is set to true.
-
##### Returns
`void`
-function that removes the watcher
-
-**`Example`**
-
-```js
-store.$onAction(({ after, onError }) => {
- // Here you could share variables between all of the hooks as well as
- // setting up watchers and clean them up
- after((resolvedValue) => {
- // can be used to cleanup side effects
-. // `resolvedValue` is the value returned by the action, if it's a
-. // Promise, it will be the resolved value instead of the Promise
- })
- onError((error) => {
- // can be used to pass up errors
- })
-})
-```
-
**`Example`**
```js
▸ (): `void`
-Setups a callback to be called whenever the state changes. It also returns a function to remove the callback. Note
-that when calling `store.$subscribe()` inside of a component, it will be automatically cleaned up when the
-component gets unmounted unless `detached` is set to true.
-
##### Returns
`void`
-
-function that removes the watcher
Ƭ **StoreOnActionListener**\<`Id`, `S`, `G`, `A`\>: (`context`: [`StoreOnActionListenerContext`](pinia.md#StoreOnActionListenerContext)\<`Id`, `S`, `G`, {} extends `A` ? [`_ActionsTree`](pinia.md#_ActionsTree) : `A`\>) => `void`
+Argument of `store.$onAction()`
+
#### Type parameters
| Name | Type |
▸ (`context`): `void`
-Argument of `store.$onAction()`
-
##### Parameters
| Name | Type |
Ƭ **SubscriptionCallback**\<`S`\>: (`mutation`: [`SubscriptionCallbackMutation`](pinia.md#SubscriptionCallbackMutation)\<`S`\>, `state`: `UnwrapRef`\<`S`\>) => `void`
+Callback of a subscription
+
#### Type parameters
| Name |
▸ (`mutation`, `state`): `void`
-Callback of a subscription
-
##### Parameters
| Name | Type |
Ƭ **\_Method**: (...`args`: `any`[]) => `any`
-#### Type declaration
-
-▸ (`...args`): `any`
-
Generic type for a function that can infer arguments and return type
For internal use **only**
+#### Type declaration
+
+▸ (`...args`): `any`
+
##### Parameters
| Name | Type |