Skip to content

Instantly share code, notes, and snippets.

@ypcode
Created November 17, 2019 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/c95f4c0804c7f87a6a011cf160189f9c to your computer and use it in GitHub Desktop.
Save ypcode/c95f4c0804c7f87a6a011cf160189f9c to your computer and use it in GitHub Desktop.
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version, ServiceScope } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import * as strings from 'UserSettingsSampleWebPartStrings';
import UserSettingsSample from './components/UserSettingsSample';
import { IUserSettingsSampleProps } from './components/IUserSettingsSampleProps';
import { UserPreferencesServiceKey, UserPreferencesService } from '../../services/UserPreferencesService';
export interface IUserSettingsSampleWebPartProps {
description: string;
}
export default class UserSettingsSampleWebPart extends BaseClientSideWebPart<IUserSettingsSampleWebPartProps> {
private _usedServiceScope: ServiceScope;
public onInit(): Promise<void> {
return super.onInit().then(() => {
// Create a child scope for the current WebPart
this._usedServiceScope = this.context.serviceScope.startNewChild();
// Configure it with the current WebPart instance Id
const serviceInstance = this._usedServiceScope.createAndProvide(UserPreferencesServiceKey, UserPreferencesService);
serviceInstance.configure(this.instanceId);
this._usedServiceScope.finish();
});
}
public render(): void {
const element: React.ReactElement<IUserSettingsSampleProps> = React.createElement(
UserSettingsSample,
{
serviceScope: this._usedServiceScope
}
);
ReactDom.render(element, this.domElement);
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment