Next.js Discord

Discord Forum

I cant figure the error out

Unanswered
Tricolored Heron posted this in #help-forum
Open in Discord
Original message was deleted.

7 Replies

Tricolored Heron
i have my data stored in sessionStorage
im trying to get the info from it but im getting this error every time
Error: Objects are not valid as a React child (found: object with keys {error, reset}). If you meant to render a collection of children, use an array instead.
thats the hook code
'use client'

import { useState, useEffect } from "react";

export default function useSession() {
    const [user, setUser] = useState<Object | null>(null);

    useEffect(() => {
        const user = sessionStorage.getItem("user");
        if (user) {
            setUser(JSON.parse(user));
        }
    }, []);
    return user;
}
and thats the navbars code
import "./custom-ui/navbarComponentStyles.css";
import Link from "next/link";
import useSession from "../hooks/useSessionStorage";

export default function Navbar() {
  const user = useSession();
  return (
    <div>
      <div>{user.nickname}</div>
      <Link href={"/"}>
        <button>Home</button>
      </Link>
      <br />
      <Link href={"/login"}>
        <button>Log out</button>
      </Link>
    </div>
  );
}
i found the hook on the internet btw