Let's suppose that we are working with a $\text{U(0,1)}$ random variable $X : \Omega \rightarrow \mathcal{X}$.
Then we define that $\mathcal{X} = \mathbb{R}$ and the probability density function of $X$ is
$ f_X(x)=\begin{cases} 1, \quad x \in [0,1],\\ 0, \quad \text{otherwise.} \end{cases} $
Why do we need to define the state space of $X$ to be $\mathcal{X} = \mathbb{R}$. Why can't we define the state space as $\mathcal{X} = [0,1]$ and the density as $f_X(x)= 1, \quad x \in [0,1]$ ?