After selling ESPP from my previous company, I received a W2 including two States. Should I file taxes for both states?

I received a W2 from my previous company after I sold its ESPP in 2022. There is no withholding on W2, but it includes two states, NC and UT. NC was the state where I lived when I worked for the company, but I moved out in 2021. UT is my resident state in 2022. Should I file taxes for both states? Thanks!