Skip to main content

useActions and useAction

info

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");
info

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"
);
note

In this example, the updateProduct action won't be available, because we have tell to useActions to get only addProduct and removeFirstProduct.


Structure

  • useActions
PropertiesTypeStatusDescription
namestringrequiredThe name of the signal. It must be unique.
...actionsstring[]optionalThe series of actions
  • useAction
PropertiesTypeStatusDescription
namestringrequiredThe name of the signal. It must be unique.
actionstringrequiredThe action name