# Is a function $f:X\to Y$ continuous if and only if its graph on each connnected component of $X$ is connected?

Let $X$ be a topological space with connected components $\{C_i\}_{i\in I}$. Let $Y$ be a topological space and let $f:X\rightarrow Y$ be a function. Then $f$ is continuous iff $$\forall i\in I, \;\{(x,f(x))\mid x\in C_i\}\text{ is a connected subspace of }X\times Y$$

The forward direction is easy, as $\{(x,f(x))\mid x\in C_i\}$ is the continuous image of the connected subspace $C_i$ (the mapping would send $x$ to $(x,f(x))$).

I am not sure if the backward direction is true for all topological spaces.

Thank you

Let $f:\Bbb R \to \Bbb R,\ x\mapsto\sin(1/x)$ if $x>0$ and $0$ otherwise. Then the graph is connected but $f$ is not continuous.
For an example where the implication works, see If the graph $G(f)$ of $f : [a, b] \rightarrow \mathbb{R}$ is path-connected, then $f$ is continuous.
I think you would need the condition of (local?) path connectivity for this to be true. Consider as a counterexample the topologist's sine curve, i.e. $f:[0,1]\to[-1,1]$ given by $$f(x)= \begin{cases} \sin\left(\frac1x\right)&x>0\\ 0&x=0 \end{cases}$$ The space $(x,f(x))$ is connected, but $f(x)$ is not continuous at $x=0$.