useActions and useAction
useActions
is available since version 1.2.0
The useActions
hook is used to retrieve actions of a signal that has been recorded in the store.
It takes the name of the signal as a the first parameter and returns an object that contains all the actions of this signal.
const { addProduct, removeFirstProduct } = useActions("product");
If you want to get the state of the signal, use the useSignal hook instead.
Assuming you want to get only one action, rather than doing this like follow:
const { addProduct } = useActions("product");
You can use the useAction
instead
const addProduct = useAction("product", "addProduct");
Also, the useActions
hooks accepts a series of actions that you want to retrieve and it will return you an object that contain actions that you asked for.
const { addProduct, removeFirstProduct, updateProduct } = useActions(
"product",
"addProduct",
"removeFirstProduct"
);
In this example, the updateProduct
action won't be available, because we have tell to useActions
to get only addProduct
and removeFirstProduct
.
Structure
- useActions
Properties | Type | Status | Description |
---|---|---|---|
name | string | required | The name of the signal. It must be unique. |
...actions | string[] | optional | The series of actions |
- useAction
Properties | Type | Status | Description |
---|---|---|---|
name | string | required | The name of the signal. It must be unique. |
action | string | required | The action name |