Sharepoint: Not able to fetch data from particular list item of site content using React APP WEB-part

sunil 96 Reputation points
2020-07-22T17:12:16.87+00:00

I am trying to fetch data from one of the list item of the site content on my SP site.

13310-screen-shot-2020-07-22-at-23855-am.png

I have built a React Webpart here are the files and code

13278-screen-shot-2020-07-22-at-114937-am.png
13279-screen-shot-2020-07-22-at-114955-am.png
13280-screen-shot-2020-07-22-at-115014-am.png
I have followed the documentation.

https://learn.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/connect-to-sharepoint

I was able to fetch the complete site content list(Document library), but when I am trying to fetch particular list using getByTitle('EmployeeList'), it fails.

Please Advice.

Thanks & Regards,

Sunil

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,204 questions
0 comments No comments
{count} votes

Accepted answer
  1. sunil 96 Reputation points
    2020-07-24T18:23:53.05+00:00

    Issue fixed: The WebPart was working fine locally by fetching data from _getMockListData.

    However, it wasn't when I was trying to test the WebPart on the https://MyOffice365.sharepoint.com/sites/**InCorrectSPSite**/_layouts/15/workbench.aspx

    I later noticed that I was pointing to wrong SP-site.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-07-23T06:19:18.177+00:00

    13591-ireactnewprops.txt13427-reactnew.txt13592-reactnewwebpart.txtYou could use pnp js to get list items.
    https://pnp.github.io/pnpjs/sp/items
    13329-r1.png
    13424-r2.png
    13370-r3.png

    Test Result:
    13359-ppp.png

    You could get the code in attachments.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.