From 13653494f4a89d2a833b19ec0f3dc912eac96f25 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 12 Apr 2019 00:58:07 +0300 Subject: Fix hook dependencies warnings (some) --- vnext/src/App.js | 2 +- vnext/src/components/Feeds.js | 55 +++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 29 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/App.js b/vnext/src/App.js index b3d821e4..4e40f9f1 100644 --- a/vnext/src/App.js +++ b/vnext/src/App.js @@ -56,7 +56,7 @@ export default function App() { es.removeEventListener('read', updateStatus); }; setEs(es); - }, []); + }, [visitor]); let search = (history, pathname, searchString) => { diff --git a/vnext/src/components/Feeds.js b/vnext/src/components/Feeds.js index 5470874b..c7b857b7 100644 --- a/vnext/src/components/Feeds.js +++ b/vnext/src/components/Feeds.js @@ -77,35 +77,34 @@ function Feed(props) { const [error, setError] = useState(false); useEffect(() => { + let loadMessages = (hash = '', filter = '') => { + document.body.scrollTop = 0; + document.documentElement.scrollTop = 0; + setMsgs([]); + const filterParams = qs.parse(filter); + let params = Object.assign({}, filterParams || {}, props.query.search || {}); + let url = props.query.baseUrl; + if (hash) { + params.hash = hash; + } + if (!params.hash && props.authRequired) { + props.history.push('/'); + } + getMessages(url, params) + .then(response => { + const { data } = response; + const { pageParam } = props.query; + const lastMessage = data.slice(-1)[0] || {}; + const nextpage = getPageParam(pageParam, lastMessage, filterParams); + setMsgs(data); + setLoading(false); + setNextpage(nextpage); + }).catch(ex => { + setError(true); + }); + }; loadMessages(props.visitor.hash, props.location.search.substring(1)); - }, [props.visitor, props.location]); - - let loadMessages = (hash = '', filter = '') => { - document.body.scrollTop = 0; - document.documentElement.scrollTop = 0; - setMsgs([]); - const filterParams = qs.parse(filter); - let params = Object.assign({}, filterParams || {}, props.query.search || {}); - let url = props.query.baseUrl; - if (hash) { - params.hash = hash; - } - if (!params.hash && props.authRequired) { - props.history.push('/'); - } - getMessages(url, params) - .then(response => { - const { data } = response; - const { pageParam } = props.query; - const lastMessage = data.slice(-1)[0] || {}; - const nextpage = getPageParam(pageParam, lastMessage, filterParams); - setMsgs(data); - setLoading(false); - setNextpage(nextpage); - }).catch(ex => { - setError(true); - }); - }; + }, [props]); let getPageParam = (pageParam, lastMessage, filterParams) => { const pageValue = pageParam === 'before_mid' ? lastMessage.mid : pageParam === 'page' ? (Number(filterParams.page) || 0) + 1 : moment.utc(lastMessage.updated).valueOf(); -- cgit v1.2.3