mirror of https://github.com/status-im/js-waku.git
Persist nick
This commit is contained in:
parent
b90b66c5f6
commit
6b48c55266
|
@ -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.
|
- 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 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.
|
- 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
|
## [0.5.0] - 2021-05-21
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,14 @@ export default function App() {
|
||||||
let [newMessages, setNewMessages] = useState<Message[]>([]);
|
let [newMessages, setNewMessages] = useState<Message[]>([]);
|
||||||
let [archivedMessages, setArchivedMessages] = useState<Message[]>([]);
|
let [archivedMessages, setArchivedMessages] = useState<Message[]>([]);
|
||||||
let [stateWaku, setWaku] = useState<Waku | undefined>(undefined);
|
let [stateWaku, setWaku] = useState<Waku | undefined>(undefined);
|
||||||
let [nick, setNick] = useState<string>(generate());
|
let [nick, setNick] = useState<string>(() => {
|
||||||
|
const persistedNick = window.localStorage.getItem('nick');
|
||||||
|
return persistedNick !== null ? persistedNick : generate();
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem('nick', nick);
|
||||||
|
}, [nick]);
|
||||||
|
|
||||||
// Waku: Start, process messages, send messages
|
// Waku: Start, process messages, send messages
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
Loading…
Reference in New Issue