react-polling
react-polling copied to clipboard
How is startPolling and stopPolling supposed to work?
First of all: great work!
But I don't understand how those two functions are supposed to work. Calling them in the render property like so
render={({ startPolling, stopPolling, isPolling }) => { if (this.state.view === 'results') { stopPolling(); } }}
leads to an TypeError:
TypeError: Cannot read property '_ismounted' of undefined
What I'd like to to is to stop polling for a certain state in the application and re-start it after another event occurs.
@K3CK Thank you for the kind words and sorry to see it not working as expected. Can you try with the latest release v1.0.5? That should fix your issue and startPolling, stopPolling should work as expected.
Let me know if you still face any issues.
Thanks for your fast response. But unfortunately it throws now a different error:
Warning: Cannot update during an existing state transition (such as within render). Render methods should be a pure function of props and state.
And
Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
can you create a codesandbox link for me to check?
I have a stupid question: I was wondering how do I get the body of the response in your example:
if(isPolling) {
return (
<div> Returned json: ? </div>
);
} else {
return (
<div> Hello I stopped polling</div>
);
}
@fjacobs the response is always returned to the onSuccess handler so you can use that and then set your own local component state. For example in a twitter feed example you can have a local component with this.state = { feeds: [] } and on every polling success you might append the new tweets to this feed.
I hope that answers your question.