Refactor to use a shared ViewMode type from the types folder instead of hardcoding string literals:
const [viewMode, setViewMode] = useState<"code" | "both" | "preview">("both"); // before
const [viewMode, setViewMode] = useState<ViewMode>(ViewMode.Both); // after
src/types/view.ts
export enum ViewMode {
Code = "code",
Both = "both",
Preview = "preview",
}
To simplify imports, you can re-export all types via:
src/types/index.ts
export * from "./view.ts";
Then just import from the folder:
import { ViewMode } from "./types";
// before
const isEditorVisible = viewMode === "code" || viewMode === "both";
const isPreviewVisible = viewMode === "preview" || viewMode === "both";
// after
const isEditorVisible = viewMode === ViewMode.Code || viewMode === ViewMode.Both;
const isPreviewVisible = viewMode === ViewMode.Preview || viewMode === ViewMode.Both;