In the name of Allāh, ar-Raḥmān (the most merciful), ar-Raḥīm (the bestower of mercy).
Seeking knowledge about Islām is an act of ‘Ibādah, and every ‘Ibādah requires a sincere intention.
When attending the Masjid, attending classes, reading a book, listening to a lesson or any other form of seeking knowledge, we should do it sincerely for the sake of Allāh; desiring to please Him and wanting His reward.
The Prophet ﷺ said,
Actions are according to intentions, and everyone will get what was intended. 
The above Ḥadīth shows us, that we will only attain the rewards of seeking knowledge if our intention is pure and sincere, because the reward of “actions is according to intentions”.
In addition to desiring reward from Allāh, we seek knowledge because we want to be better Muslims, to be learned Muslims and not ignorant Muslims.
Imām Aḥmad said,
There is nothing equal to knowledge, for a person who has a sincere intention.
The people asked him,
“O Abu Abdullāh, how do we have a correct intention?
You intend to remove ignorance from yourself and then others. 
 Narrated by ‘Umar; Collected by al-Bukhārī & Muslim.
 Ādāb ash-Sharī’ah by Ibn Mufliḥ.