SharePoint/PnP-JS-Core

Get list items keeps firing requests

Closed this issue · 3 comments

Category

[ ] Question

Version

SharePointPnPPowerShellOnline 2.25.1804.1
SharePointPnPPowerShellOnline 2.22.1801.0

Question

When I retrive listitems like this

pnp.sp.web.lists.getByTitle("MyList").items.select("Title,Active,Severity").filter('Active eq 1').top(5).get().then(
(data:any[])=>{this.setState({listItems:data})}
);

I can see, by looking in the networkexplorer in Google Chrome that the page keeps requesting

/items?$select=Title,Active,Severity&$filter=Active%20eq%201&$top=5

What am I doing wrong?

Thanx in advance

Hey @nda1974,

It's likely that it's an issue in your React component. I.e. if exclude setState would it be a recursion?
One of the possible reasons, for example,. is requesting async data and executing setState in render method.

P.S.

Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being deprecated in July 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!

Going to close this as it appears answered. Thanks!

Yes the problem is solbed, the reason was, as koltyakov wrote, caused by executing the call from the render method. Thanx a lot for quick response.