aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/App.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-06-11 10:44:10 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:55 +0300
commit6c13742f1d01869abc05e22ce2208fce1aafbf1f (patch)
tree4e74de68805cae9ab23c49622b5ec03d0c92329c /vnext/src/App.js
parent49777aad64853874ed77682657565445c6aaac8d (diff)
remove incorrect useEffect dependency on visitor state
Diffstat (limited to 'vnext/src/App.js')
-rw-r--r--vnext/src/App.js18
1 files changed, 11 insertions, 7 deletions
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 (
<Router>