Let $A$ and $B$ be non-empty sets, and let $f\,:\,A\rightarrow B$ be a function.
$ \color{darkred}{\bf Theorem}$: The function $f$ is injective if and only if $f\circ g=f\circ h$ implies $g=h$ for all functions $g,h:\,Y\rightarrow A$ for all sets Y. ($f\,:\,A\, \rightarrowtail \,B$, $f$ is a monomorphism)
I want to prove this ${\bf {\it theorem}}$, but I get stuck.
$\color{darkred}{\bf proof\,\,}$:
$\Rightarrow$) Assume that $f$ is injective. Let $g,h:\,Y\rightarrow A$ be functions such that $f\circ g(y)=f\circ h(y),\,\,\,\,\,\,y\in Y$ it follows that $f(g(y))=f(h(y))$, and $f$ is injective, therefore $g(y)=h(y)$ for every $y\in Y$.
$\Leftarrow$) and here I get stuck, can’t figure out how to prove this.
Can someone help me with this proof?