Velo: About Data Hooks

Visit the Velo by Wix website to onboard and continue learning.

Data hooks run code before or after certain interactions with your site's collections. A data hook allows you to intercept the interaction immediately before or immediately after it occurs. The hook's code can even be used to affect the interaction itself. For example, you may want to intercept an item before it is added to your collection to perform a final validation or to tweak the data that actually makes it into the collection.

In general, hooks are run whether the interaction with your collection is initiated by a page element or programmatically using the Data API. However, a Data API call from the backend code of your site may pass the optional WixDataOptions object and use it to suppress hooks from being called on that particular interaction.

See Using Data Hooks to find out how to register hooks on your collections.

Hook Types

There are a number of different points in the lifecycle of a data interaction that you can hook into. Different hooks receive different arguments and return different values. For more information, see the Data API reference.

  • item: The current item. For example, in beforeInsert, this is the item that is about to be inserted. If there are many items, such as can happen with afterQuery for example, the hook function will be called repeatedly, once for each of the items.
  • itemId: The current item's ID value.
  • query: The WixDataQuery object that will be executed.
  • count: The number of items in the count.
  • error: An error object.
Hook NameReceives
beforeInsertitem
afterInsertitem
beforeUpdateitem
afterUpdateitem
beforeRemoveitemId
afterRemoveitem
beforeGetitemId
afterGetitem
beforeQueryquery
afterQueryitem
beforeCountquery
afterCountcount
onFailureerror
Was this helpful?
Yes
No