Access to initial state in lifecycle hooks

Hello everyone,
Inside the afterUpdate hook i need to check if one specific property changes. With event.params.data i have access to the updated data, but i need to have access to the data before it is updated as well. The docs says that this should be possible with event.state, but this object is always empty.
Any help is greatly appreciated!

This topic has been created from a Discord post (1257261318310727753) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

Hi this not possible in after hook

But there is state variable that you can pass from before hook to after hook

Thanks for your answer. In my case events.state is an empty object. In the beforeUpdate-Hook as well as in the afterUpdate-Hook. I am trying to get it to work in the users-permissions Plugin. I want if the users blocked-property changes. Might that be different in the plugin than in core?

Do you set the event.state during before hook?

I did. But i the beforeUpdate- Hook i cannot get the data before it is updated. Or do i have the get the data manually with the Entity Service API?

You have to get manually yes

Then set it to state