Take passing page context from webpart to component as example(this will be use often).(以从Webpart到组件传递页面上下文为例(这将经常使用)。)
In component property interface,add the property which you need to get from webpart(.ts).(在组件属性界面中,添加需要从webpart(.ts)获取的属性。)
The context will pass from .ts.(上下文将从.ts传递。)
import { WebPartContext } from '@microsoft/sp-webpart-base';
export interface IPnpReactProps {
description: string;
context: WebPartContext;
}
In webpart(.ts) file, the context will pass to component(.tsx).(在webpart(.ts)文件中,上下文将传递到component(.tsx)。)
public render(): void {
const element: React.ReactElement<IPnpReactProps > = React.createElement(
PnpReact,
{
description: this.properties.description,
context:this.context
}
);
ReactDom.render(element, this.domElement);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…