Skip to content

Instantly share code, notes, and snippets.

@dburles
Created May 16, 2018 02:55
Show Gist options
  • Select an option

  • Save dburles/c8a6921fcfd4c0f40a9f805d0c9fd437 to your computer and use it in GitHub Desktop.

Select an option

Save dburles/c8a6921fcfd4c0f40a9f805d0c9fd437 to your computer and use it in GitHub Desktop.
class Polling extends React.Component {
componentDidMount() {
this.intervalId = setInterval(this.props.callback, this.props.interval);
}
componentWillUnmount() {
clearInterval(this.intervalId);
}
render() {
return this.props.children;
}
}
@jaydenseric

jaydenseric commented May 16, 2018

Copy link
Copy Markdown

Perhaps you could use that something like this:

const PollingQuery = ({ interval, children, ...queryProps }) => (
  <Query {...queryProps}>
    {queryRenderArgs => (
      <Polling interval={interval} callback={queryRenderArgs.load}>
        {children(queryRenderArgs)}
      </Polling>
    )}
  </Query>
)

@jaydenseric

jaydenseric commented May 16, 2018

Copy link
Copy Markdown

I'm pretty sure that loads of the same query that is in flight await the inflight request instead of sending a new request. So it should be safe to aggressively poll?

@dburles

dburles commented May 16, 2018

Copy link
Copy Markdown
Author

That looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment