No calamity befalls on the earth or in yourselves
but is inscribed in the Book of Decrees (Al-Lauh Al-Mahfuz),
before We bring it into existence. Verily, that is easy for Allah.
In order that you may not grieve at the things that you fail to get,
nor rejoice over that which has been given to you.
And Allah likes not prideful boasters.
In this Ayah, Allah s.w.t. tells us of His encompassing knowledge, recording all things before they occur and creating all things in due measure known to Him, so that we may know that what has met us would never have missed us, and what has missed us would never have come to us.
Therefore, do not grieve for what we may have missed – that job, that promotion, that man or woman – because had it been destined for us, we would have achieved it. So be kind to your heart and say to yourself that Allah’s plan is far better than mine.
Nor boast to people about what Allah has favored us with. Everything that we earned is not through our efforts, but rather, all this came because Allah s.w.t. has destined them for you.
So make your joy with gratitude, and endure your grief with patience. Such is the characteristics of a person who has tawakkul in Allah.
Tafsir Ibn Kathir