diff --git a/CHANGELOG.md b/CHANGELOG.md index 828206308d..3e7dcc8bcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Examples (web chat): Use `WakuMessage.timestamp` as unique key for list items. - Doc: Link to new [topic guidelines](https://rfc.vac.dev/spec/23/) in README. - Doc: Link to [Waku v2 Toy Chat specs](https://rfc.vac.dev/spec/22/) in README. +- Examples (web chat): Persist nick. ## [0.5.0] - 2021-05-21 diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index 1a7d9b30f3..b4a3a71d6b 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -77,7 +77,14 @@ export default function App() { let [newMessages, setNewMessages] = useState([]); let [archivedMessages, setArchivedMessages] = useState([]); let [stateWaku, setWaku] = useState(undefined); - let [nick, setNick] = useState(generate()); + let [nick, setNick] = useState(() => { + const persistedNick = window.localStorage.getItem('nick'); + return persistedNick !== null ? persistedNick : generate(); + }); + + useEffect(() => { + localStorage.setItem('nick', nick); + }, [nick]); // Waku: Start, process messages, send messages useEffect(() => {