score:0

Accepted answer
const [account,setAccount] = useState(localStorage.getItem('account') ?localStorage.getItem('account') : null)
    useEffect(()=>{
localStorage.setItem('account',account)
},[account])
    const handleClick = () => {
        setAccount(randomNumberThatIHaveGenerated)
    }

score:1

const [account,_setAccount] = useState();
const setAccount = (val) => {
  _setAccount(val);
  localStorage.setItem('account', val);
}

useEffect(() => {
  const storedAccount = localStorage.getItem('account');
  if (storedAccount) _setAccount(storedAccount);
}, [])
    
const handleClick = () => {
  setAccount(randomNumberThatIHaveGenerated)
}

Related Query

More Query from same tag