As long as it is an original Apple SSD it should work as long it is the same model year (other model years...maybe). If it is a third party NVMe SSD, then it may depend on the system firmware version of the used laptop (needs macOS 10.13+).
You should seriously consider frequent & regular backups. Consider yourself very lucky if you can retrieve data from the SSD this time. Next time you will not be so lucky because most of Apple's recent Macs have their SSDs soldered to the Logic Boards with no hope of being able to recover any data if the Logic Board is not functional. Also, keep in mind that SSDs can fail at any time without any warning signs and even if you have a warning sign, it may be too late. Plus it is impossible to recover accidentally deleted data after the Trash has been emptied.
You should always have frequent and regular backups of your computer and all external media (including the cloud) which contains important & unique data.