create a state change listner