#Preventing Unnecessary Field Hooks on Value Update

9 messages · Page 1 of 1 (latest)

slate coveBOT
#

New to payload here, is there a way to prevent a field hooks from executing unless the fields value has been updated ?

pseudo mossBOT
#

Original message from @keen kettle - Moved from #general message

pallid bloom
#

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.

keen kettle
#

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

pallid bloom
#

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