In this blog, you will see how to create list item using PnP JS in SharePoint Framework.

@pnp/sp

This package contains the fluent api used to call the SharePoint rest services. Refer to this link for more details.

Create List Item

Create SPFx solution
Open Node.js command prompt.
Create a new folder.
Navigate to the folder.
Execute the following command to create SPFx webpart.
Enter all the required details to create a new solution. Enter the webpart named CreateItem and select React framework.
Yeoman generator will perform scaffolding process and once it is completed, lock down the version of project dependencies by executing the following command.
Execute the following command to open the solution in the code editor.
Execute the following command to install the pnp sp library.
Create a new file named as “ICreateItemState.ts” under Components folder and update the code as shown below.
Open the component file “src\webparts\createItem\components\CreateItem.tsx” and update the code as shown below.
Open the webpart file “src\webparts\createItem\CreateItemWebPart.ts” and add the OnInit() method.

Deploy the solution

Execute the following commands to bundle and package the solution.
Navigate to tenant app catalog – Example: https://c986.sharepoint.com/sites/appcatalog/SitePages/Home.aspx
Go to Apps for SharePoint library and upload the package file (sharepoint\solution\spfx-pnpjs-createitem.sppkg). Click Deploy.

Test the webpart

Navigate to the SharePoint site and add the app. Navigate to the page and add the webpart.
Result

Summary

Thus, in this blog, you saw how to create list items using PnP JS in SharePoint Framework.
hostforlifebanner