Added nickname to local storage
This commit is contained in:
parent
16ba3c3a63
commit
64f284ebb7
16
src/helpers/useNickname.js
Normal file
16
src/helpers/useNickname.js
Normal 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;
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user