Yahya related to me from Malik from Rabia ibn Abi Abd ar-Rahman from Umm Salama, the wife of the Prophet may Allah bless him and grant him peace, that the Messenger of Allah (ﷺ) said, "If a misfortune befalls some one and he says, as Allah has ordered, 'We belong to Allah and to Him we are returning. O Allah, reward me in my misfortune and give me better than it afterwards,' Allah will do that for him" (Inna lillahi wa inna ilayhi rajiun. Allahumma' jurniy fi musiybatiy, wa a qibhiy khayran minha, illa faala 'llahu dhalika bihi.).
Umm Salama said, "When Abu Salama died I said that, and then I said, 'Who is better than Abu Salama?' " And then Allah left her the Messenger of Allah (ﷺ) and he married her.