You can use
UnitIsVisible to make sure you even have a pet. The function HidePetActionBar is used in the default UI whenever the pet is dismissed, this includes when it "vanishes," so hooking it works alongside UnitIsVisible to determine whether it's dead or vanished/despawned.