-
-
Save ypcode/c95f4c0804c7f87a6a011cf160189f9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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