Purity of intention is essential in all deeds.
Narrated Abu Huraira (may Allah be pleased with him): I heard Allah’s Messenger (Peace be upon him) saying:
“The first of the people whose case will be decided on the Day of Judgment will be a man who died as a martyr. He will be brought forth. Allah will make him know about His blessings (which He had bestowed on him in the world). The man will acknowledge them. Then Allah will ask him: What did you do with them? He will say: I fought in Your way until I died as a martyr. Allah will remark: You are lying. You fought so that you may be called a brave warrior. Then orders will be passed against him. So he will be dragged along on his face and cast into Hell.
Second will be a man who studied (religious) knowledge. Then he taught it to others and recited the Qur’an. He will be brought (for Judgment). Allah will remind him of His favours (showered on him in the world). He will admit them (having enjoyed them in his life). Then Allah will ask him: What did you do with them? He will reply: I acquired knowledge and imparted it and also recited the Qur’an for Your sake. Allah will observe: You have told a lie, for you got knowledge to be renowned as a scholar; and you recited the Qur’an to be marked as a Qari (one who recites the Qur’an according to the rules). Then orders will be passed against him. So he will be dragged along on his face and thrown into Hell.
Third will be a man to whom Allah had made abundantly rich and granted him every kind of wealth. He will be brought for Judgment. Allah will let him know about His gifts conferred upon him in the world. He will recognize them. Then Allah will inquire: What did you with them? He will say: I left no way in which you like money to be spent without spending in it for your sake. Allah will say: You are lying. You did so to be described as generous (in the society); (It means you got your reward in the world according to your intention). Now you deserve nothing in the Hereafter except Hell). So orders will be passed against him and he will be dragged along on his face until he will be hurled into Hell.”
(This Hadith is sound and reported by Muslim and Nasa’i)
The purity of intention is behind any deed. If you spend for show, there is no reward. Eventually, if one loves another for something worldly this shall not count in the Hereafter. But love for the sake of Allah is great virtue in the Hereafter. Such love can be a Muslim’s love to learn from him or to take as a companion for good deeds, without any worldly considerations, once there is something worldly, the intention is not pure.