diff options
author | Vitaly Takmazov | 2019-06-11 10:28:21 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:55 +0300 |
commit | 49777aad64853874ed77682657565445c6aaac8d (patch) | |
tree | 4cc18c215588d5155b8e712194cd4b7dd0da9d87 /vnext | |
parent | 0aef5bbe5bc900f958961fcd5803099f1f485547 (diff) |
remove incorrect useEffect dependency
Diffstat (limited to 'vnext')
-rw-r--r-- | vnext/src/App.js | 14 |
1 files changed, 7 insertions, 7 deletions
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() { } /> <Route exact path="/post" render={(props) => <Post visitor={visitor} {...props} />} /> <Route exact path="/pm" render={(props) => <Contacts visitor={visitor} {...props} />} /> - <Route exact path="/pm/:user" render={(props) => <Chat connection={es} visitor={visitor} {...props} />} /> + <Route exact path="/pm/:user" render={(props) => <Chat connection={eventSource} visitor={visitor} {...props} />} /> <Route exact path="/:user/friends" render={(props) => <Friends visitor={visitor} {...props} />} /> <Route exact path="/:user/readers" render={(props) => <Readers visitor={visitor} {...props} />} /> <Route exact path="/:user" render={(props) => <Blog visitor={visitor} {...props} />} /> <Route exact path="/tag/:tag" render={(props) => <Tag visitor={visitor} {...props} />} /> - <Route exact path="/:user/:mid" render={(props) => <Thread connection={es} visitor={visitor} {...props} />} /> + <Route exact path="/:user/:mid" render={(props) => <Thread connection={eventSource} visitor={visitor} {...props} />} /> </Switch> </section> { |