On logging into my NextJS application, I am saving some user data to local storage.
I am trying to render this into a small component which always displays the users name. The issue i am getting is that it is only sometimes showing and other times it is displaying as null ... It seems when i log in, it displays as null, but when i reload the page it works.
This is what I have;
import { useEffect } from 'react';
export default function ProfileDisplay() {
useEffect(async () => {
const userName = JSON.parse(localStorage.getItem('profile'));
console.log(userName);
}, []);
return (
<div>
{userName}
</div>
)
}