The relevance isn’t wholly work hours but rather “work for hire,” I.e. if it’s in the scope of your paid responsibilities.
A handful of states including California disallow this condition.