Prophet Muhammad ﷺ forbade a person should say, after missing something:”If only I had done such and such, then such and such would have happened.’”
Instead, he ﷺ guided us to what is more beneficial than that, which is to say “Qaddarallahu wa maa sha’a fa’ala”(Allah has ordained and as He willed, He has done).
This is because ‘If only’ opens the door to the Shaytaan”, i.e. it makes you vulnerable to grief and fear, which is harmful to you and is of no benefit. Know that whatever befalls you, you could not have avoided, and whatever does not happen to you, you could not have made it happen to you, as Allah says in the Quran:
“مَا أَصَابَ مِنْ مُصِيبَةٍ إِلَّا بِإِذْنِ اللَّهِ ۗ وَمَنْ يُؤْمِنْ بِاللَّهِ يَهْدِ قَلْبَهُ ۚ وَاللَّهُ بِكُلِّ شَيْءٍ عَلِيمٌ
No disaster strikes except by permission of Allah . And whoever believes in Allah – He will guide his heart. And Allah is Knowing of all things. (At-Taghabun, 11)