From 49777aad64853874ed77682657565445c6aaac8d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 11 Jun 2019 10:28:21 +0300 Subject: remove incorrect useEffect dependency --- vnext/src/App.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/App.js b/vnext/src/App.js index 51c255a6..483ec73c 100644 --- a/vnext/src/App.js +++ b/vnext/src/App.js @@ -12,7 +12,6 @@ import Post from './ui/Post'; import Thread from './ui/Thread'; import LoginButton from './ui/LoginButton'; import { UserLink } from './ui/UserInfo'; -import Header from './ui/Header'; import SearchBox from './ui/SearchBox'; import cookies from 'react-cookies'; @@ -37,16 +36,17 @@ export default function App() { }); }; - const [es, setEs] = useState({}); + const [eventSource, setEventSource] = useState({}); useEffect(() => { const { hash } = visitor; + let es; if (hash) { me().then(visitor => auth(visitor)); if ('EventSource' in window) { const eventParams = { hash: hash }; let url = new URL(`https://juick.com/api/events?${qs.stringify(eventParams)}`); - let es = new EventSource(url); + es = new EventSource(url); es.onopen = () => { console.log('online'); }; @@ -56,11 +56,11 @@ export default function App() { }; es.addEventListener('read', updateStatus); es.addEventListener('msg', updateStatus); - setEs(es); + setEventSource(es); } } return (() => { - if (es.removeEventListener) { + if (es && es.removeEventListener) { es.removeEventListener('read', updateStatus); es.removeEventListener('msg', updateStatus); } @@ -134,12 +134,12 @@ export default function App() { } /> } /> } /> - } /> + } /> } /> } /> } /> } /> - } /> + } /> { -- cgit v1.2.3