0

I use PnPJS within an REST API route like this:

pnp.sp.web.lists.getByTitle("t").reserveListItemId().then(v => {
    pnp.sp.web.lists.getByTitle("t").items.add({
        ID: v,
        Title: v.toString(),
    }).then(function (Data) {
    // codes
    });
})

but utilizing it this way, I can access the current site only.

How can I get access to a list item or create one in a list of a subsite?

jimas13
  • 597
  • 5
  • 19

1 Answers1

0

According to my research and testing, please try to use the following code to access subsite:

import { Web } from "@pnp/sp/webs";   
export interface IDataFromOtherScState {  
   listItems: any;  
}   
private web = Web("https://testinglala.sharepoint.com/sites/Test/subsite");   
public componentDidMount = () => {  
    this.web.lists.getByTitle("Employee").items().then((items) => {  
        this.setState({  
            listItems: items  
        });  
    }).catch((err) => {  
        console.log(err);  
    });  
}   

More information for reference: Use PnP JS To Fetch List Items From Other Site Collection In SharePoint Online

Zella_msft
  • 372
  • 2
  • 4