Reversible topotactic redox reactions of layered dichalcogenides