Confusion for beforeUpdate datahook

Hi. Just wanted to clarify for the beforeUpdate webhook https://www.wix.com/velo/reference/wix-data/hooks/beforeupdate

On updating a database row, I wanted to get the value of the previous data which was updated rather than the new data.

I assumed the beforeUpdate hook does that, but it only returns the new value of the database row.

Is that how it is supposed to work?

What’s the difference then between this and afterUpdate hook?

The idea of the beforeUpdate hook is that it gives the developer a chance to do something with the new data that is about to be updated. For example, ensuring a certain field is upper/lower case, adding a default value, or whatever.

As far as getting the “previous” data, a typical scenario with update would be to first do a query and get the data that is currently in the collection. Then, using that data, the required changes are made, and then the update is performed. So, instead of using a hook to get the “previous” data, you would be getting the “previous” data from the initial query.

See the article Using Data Hooks for some use cases, examples, and further explanation.

Thanks for the explanation @yisrael-wix !