With Hooks, you can transform Payload from a traditional CMS into a fully-fledged application framework.
lastModifiedBydata to a document to track who changed what over time
ContactSubmissions are created from a public website
Orders that users submit is accurate and valid
lastLoggedIndate on a user by adding an
There are many more use cases for Hooks and the sky is the limit.
All hooks can be written as either synchronous or asynchronous functions. If the Hook should modify data before a document is updated or created, and it relies on asynchronous actions such as fetching data from a third party, it might make sense to define your Hook as an asynchronous function, so you can be sure that your Hook completes before the operation's lifecycle continues. Async hooks are run in series - so if you have two async hooks defined, the second hook will for the first to complete before it starts.
If your Hook simply performs a side-effect, such as updating a CRM, it might be okay to define it synchronously, so the Payload operation does not have to wait for your hook to complete.
Payload Hooks do not have any effect within the Payload Admin panel. You can safely remove your hooks from your Admin panel's code by customizing the Webpack config, which not only keeps your Admin bundles' filesize small but also ensures that any server-side only code does not cause problems within browser environments.
You can specify hooks in the following contexts: