Ibn Rajab and others gave an account of a worshipper who ran out of resources while he was in Makkah. He became extremely hungry and was about to die from lack of nourishment.
One day, as he was wandering in the precincts of Makkah, he found an expensive necklace. He put it into his sleeves and headed for the Masjid.
On his way he came across a man announcing that he had lost a necklace. The poor man later said, "I asked him to describe it to me, and he did so, perfectly, leaving no room for doubt. I gave him the necklace without taking reward from him.
I said,: "O Allah, I have given it for You, so compensate me with what is better."
The man went to the ocean and began a journey in a small boat. Only a brief period of time passed before a storm came with heavy winds crashing into the boat.
The boat smashed into pieces and the man was forced to cling to a piece of wood. The winds were violent, propelling him to the left and to the right.
Finally, he was washed ashore onto an island. He found there a Masjid filled with people who were praying, so he joined them. He found papers with parts of the Qur'an written on them and he began to recite from them.
The people of the island asked him, "Do you read Qur'an?" He answered in the affirmative.
"Teach our children Qur'an," they said. So he began to teach them and he took a salary for his services.
One day, they saw him writing and they asked, "Will you teach our children to write?". Again he answered in the affirmative and began teaching them for a salary.
A short time later, they said to him, "There is an orphaned girl with us whose father was a good man. Will you marry her?"
He agreed to the marriage and later related, "I married her and found that she was wearing the exact same necklace. She said that her father lost it in Makkah and a man found it and returned to him. She said that her father would always supplicate while prostrating, for her daughter to become blessed with a husband similiar to the honest man. I then informed her that I was that man."
Umm Salamah reported: I heard the Messenger of Allah (salAllahu alayhi wasalam) saying,
Inna lillahi wa inna ilaihi raji`un. Allahumma ujurni fi musibati, wakhluf li khairan minha
We belong to Allah and to Him we shall return. O Allah! Compensate me in my loss, recompense my loss and give me something better in exchange for it.
Abandoning something for the sake and Pleasure of Allah - Allah will definitely compensate with something that is better, either sooner or later, in this world or Hereafter.
Source: Don't be Sad - Shaykh Aaidh ibn Abdullah Al-Qarni