Added nickname to local storage

This commit is contained in:
Mitchell McCaffrey 2020-04-15 20:18:59 +10:00
parent 16ba3c3a63
commit 64f284ebb7
2 changed files with 18 additions and 2 deletions

View File

@ -0,0 +1,16 @@
import { useEffect, useState } from "react";
import { getRandomMonster } from "./monsters";
function useNickname() {
const [nickname, setNickname] = useState(
localStorage.getItem("nickname") || getRandomMonster()
);
useEffect(() => {
localStorage.setItem("nickname", nickname);
}, [nickname]);
return { nickname, setNickname };
}
export default useNickname;

View File

@ -10,7 +10,7 @@ import { useParams } from "react-router-dom";
import { omit, isStreamStopped } from "../helpers/shared";
import useSession from "../helpers/useSession";
import { getRandomMonster } from "../helpers/monsters";
import useNickname from "../helpers/useNickname";
import Party from "../components/Party";
import Tokens from "../components/Tokens";
@ -74,7 +74,7 @@ function Game() {
}
}
const [nickname, setNickname] = useState(getRandomMonster());
const { nickname, setNickname } = useNickname();
const [partyNicknames, setPartyNicknames] = useState({});
function handleNicknameChange(nickname) {