From 6c13742f1d01869abc05e22ce2208fce1aafbf1f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 11 Jun 2019 10:44:10 +0300 Subject: remove incorrect useEffect dependency on visitor state --- vnext/src/App.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/App.js b/vnext/src/App.js index 483ec73c..bad57fc4 100644 --- a/vnext/src/App.js +++ b/vnext/src/App.js @@ -14,19 +14,18 @@ import LoginButton from './ui/LoginButton'; import { UserLink } from './ui/UserInfo'; import SearchBox from './ui/SearchBox'; -import cookies from 'react-cookies'; +import cookie from 'react-cookies'; import { me } from './api'; export default function App() { let params = qs.parse(window.location.search.substring(1)); if (params.hash) { - cookies.save('hash', params.hash, { path: '/' }); + cookie.save('hash', params.hash, { path: '/' }); window.history.replaceState({}, document.title, `${window.location.protocol}//${window.location.host}${window.location.pathname}`); } const [visitor, setVisitor] = useState({ - uid: 0, - hash: cookies.load('hash') + uid: 0 }); let updateStatus = () => { @@ -36,10 +35,10 @@ export default function App() { }); }; + const [hash, setHash] = useState(cookie.load('hash')); const [eventSource, setEventSource] = useState({}); useEffect(() => { - const { hash } = visitor; let es; if (hash) { me().then(visitor => auth(visitor)); @@ -65,7 +64,7 @@ export default function App() { es.removeEventListener('msg', updateStatus); } }); - }, [visitor.hash]); + }, [hash]); let search = (history, pathname, searchString) => { let location = {}; @@ -74,7 +73,12 @@ export default function App() { history.push(location); }; let auth = (visitor) => { - setVisitor(visitor); + setVisitor(prevState => { + if (visitor.hash != prevState.hash) { + setHash(visitor.hash); + } + return visitor; + }); }; return ( -- cgit v1.2.3