#Preventing Unnecessary Field Hooks on Value Update
9 messages · Page 1 of 1 (latest)
Original message from @keen kettle - Moved from #general message
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
- Field Hooks - Config Options - beforeDuplicate
- Field Hooks - Config Options - afterChange
- Field Hooks - Config Options - beforeChange
Community-Help:
Hey @keen kettle
Yes, this is possible - many ways to do this honestly.
All field hooks should receive a previousValue prop passed into it, you could compare your current value to the previous to dictate whether or not to run your logic. If you deem that it's not necessary to run, then just return early with the appropriate value.
See here in the table: https://payloadcms.com/docs/hooks/fields#config-options
Thanks @pallid bloom
would it be better if this behavior is integrated into payload ? where the field hooks won't run unless the fields value has changed
Probably not
Keep in mind that this would make it a breaking change
But also, doing too much on behalf of the user is also probably not ideal, rather give the user the capability to decide what to do