(a) Metals generally do not react with hydrogen. But some reactive metals like sodium, potassium, calcium and magnesium can force the hydrogen atom to accept the electrons given by them and form salt-like ionic solid compounds called metal hydrides.
For example:
2Na(s) + H2(g) 2NaH(s)
(b) Non-metals react with hydrogen by sharing their electrons with hydrogen electrons to form covalent hydrides.
For example: Sulphur shares its electrons with hydrogen electrons to form hydrogen sulphide that is covalent in nature.
H2(g) + S(l) H2S (g)