Add hooks before and after a state change.

Useful for plugin authors.