From 6881f15613fcf8557224c3cbfb52a23439cfc8b9 Mon Sep 17 00:00:00 2001 From: Sergey Poznyak Date: Thu, 25 Oct 2018 11:16:53 +0300 Subject: [PATCH] Fixed polling queries not updating params --- lib/withStaticQuery.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/withStaticQuery.js b/lib/withStaticQuery.js index 8108cb9..b9e2d62 100644 --- a/lib/withStaticQuery.js +++ b/lib/withStaticQuery.js @@ -14,19 +14,27 @@ export default function withStaticQueryContainer(WrappedComponent) { }; componentWillReceiveProps(nextProps) { - const {query} = nextProps; - this.fetch(query); + this.startPolling(); } componentDidMount() { - const {query, config} = this.props; + this.startPolling(); + } + + startPolling() { + const { config, query } = this.props; + this.fetch(query); - if (config.pollingMs) { - this.pollingInterval = setInterval(() => { - this.fetch(query); - }, config.pollingMs) + if (!config.pollingMs) return; + + if (this.pollingInterval) { + clearInterval(this.pollingInterval) } + + this.pollingInterval = setInterval(() => { + this.fetch(query); + }, config.pollingMs); } componentWillUnmount() { @@ -73,4 +81,4 @@ export default function withStaticQueryContainer(WrappedComponent) { GrapherStaticQueryContainer.displayName = `StaticQuery(${getDisplayName(WrappedComponent)})`; return GrapherStaticQueryContainer; -} \ No newline at end of file +}