TwitchClone / src / utils / helpers / getStoredData / index.tsx
index.tsx
Raw
import { RoomDataSchema } from "../../../types/roomData";
import { UserSchema } from "../../../types/user";

export const getStoredData = (
  key: string
): RoomDataSchema | UserSchema | null => {
  if (typeof window !== "undefined") {
    const storedData = localStorage.getItem(key);
    return storedData
      ? (JSON.parse(storedData) as RoomDataSchema | UserSchema)
      : null;
  }
  return null;
};