setDataAtCell

This result from that you can’t use setDataAtCell inside afterChange.

I think the better option is checking the upcoming data in the beforeChange hook.
Just like we write in the docs: Its main purpose is to alter changes silently after input and before
table rendering. - https://handsontable.com/docs/7.4.2/Hooks.html#event:beforeChange

But you have to operate on the changes array itself.
You can’t use setDataAtCell in beforeChange too.