Saving the feedback

Now we are ready to save the data to the SharePoint list. We are going to do it using REST API but, to help us out, we are using SPHttpClient class. If we are running on a local workbench, that will not work, so we need to know the environment type before trying to save the data and act accordingly. Open FeedbackWebPart.ts and insert the following import statement after the other import statements at the start of the file:

import { SPHttpClient, ISPHttpClientOptions, SPHttpClientResponse } from '@microsoft/sp-http'; import { Environment, EnvironmentType } from '@microsoft/sp-core-library'; 

Replace the sendFeedback function with the following code.

 private sendFeedback(): void {  this.context.statusRenderer.clearError(this.domElement); ...

Get SharePoint Development with the SharePoint Framework now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.