add state callback to get query id and to hook state change of queries