react-polling icon indicating copy to clipboard operation
react-polling copied to clipboard

How is startPolling and stopPolling supposed to work?

Open K3CK opened this issue 6 years ago • 5 comments

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 avatar May 23 '19 09:05 K3CK

@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.

vivek12345 avatar May 23 '19 09:05 vivek12345

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.

K3CK avatar May 23 '19 10:05 K3CK

can you create a codesandbox link for me to check?

vivek12345 avatar May 23 '19 10:05 vivek12345

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 avatar Sep 20 '19 13:09 fjacobs

@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.

vivek12345 avatar Sep 20 '19 13:09 vivek12345