Change tile with collision

Godot Version

4.5.1

Question

Lets say you have tile A and B in a TileMapLayer, and A has been placed into the game.

How would you cause the tile to change to tile B while it is within a collision shape, and revert back to A once the collsion shape has left.

PS I am a beginner and not all that familiar with GDScript