I was working on a SharePoint Framework webpart,
especially on the property pane, and needed to understand when the SPFx WebPart
lifecycle methods are executed. Specifically, the order in which they are
fired.
The Microsoft docs on these methods/APIs are
fairly extensive and they give a good overview of what each method does:
https://docs.microsoft.com/en-us/javascript/api/sp-webpart-base/baseclientsidewebpart?view=sp-typescript-latest#methods
https://docs.microsoft.com/en-us/javascript/api/sp-webpart-base/basewebpart?view=sp-typescript-latest
SPFx
webpart method execution order:
When loading the web part on a page, the methods
are fired in the following order:
1) protected onAfterDeserialize(deserializedObject:
any, dataVersion: Version):
TProperties;
2) protected onInit(): Promise<void>;
3) protected render(): void;
4) protected onBeforeSerialize(): void;
When the web part is removed from a
page, the methods are fired in the following order:
1) protected onDispose(): void;
SPFx
webpart property pane method execution order:
Opening the
property pane:
1) protected loadPropertyPaneResources(): Promise<void>
2) protected getPropertyPaneConfiguration():
IPropertyPaneConfiguration;
3) protected onPropertyPaneRendered(): void;
4) protected onPropertyPaneConfigurationStart(): void;
Updating the properties in the property pane:
The SPFx property pane can be set in either the
reactive mode or in a non-reactive mode:
"Reactive implies that changes made in the
PropertyPane are transmitted to the web part instantly and the user can see
instant updates. This helps the page creator get instant feedback and decide if
they should keep the new configuration changes or not.
NonReactive implies that the configuration changes are
transmitted to the web part only after "Apply" PropertyPane button is
clicked."
When in reactive mode, if any property is
changed, the methods are fired in the following order:
1) protected
onPropertyPaneFieldChanged(propertyPath: string, oldValue: any, newValue: any): void;
2) protected render(): void;
3) protected getPropertyPaneConfiguration():
IPropertyPaneConfiguration;
4) protected onPropertyPaneRendered(): void;
5) protected
onPropertyPaneConfigurationComplete(): void;
When in non-reactive mode, if any property is
changed, the methods are fired in the following order:
1) protected
onPropertyPaneFieldChanged(propertyPath: string, oldValue: any, newValue: any): void;
2) protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration;
3) protected onPropertyPaneRendered(): void;
When in
non-reactive mode, after clicking on the "Apply" button, the
methods are fired in the following order:
1) protected
onAfterPropertyPaneChangesApplied(): void;
2) protected render(): void;
3) protected
onPropertyPaneConfigurationComplete(): void;
4) protected onPropertyPaneRendered(): void;
When the property
pane is closed by clicking on the "X" button
1) protected
onPropertyPaneConfigurationComplete(): void;
Aucun commentaire: