Dec 21 2018 07:11 AM
Hi,
I want to begin developing web parts with SPFx + React + Pnp but I can't find samples using this tools together.
I found this page that show how to use Pnp: Here and as you can see its focus in just Pnp.
Then I found this one showing how to get list items using Pnp: This one but is not using React at all.
So I decided to give it a try and try to start learning by doing, but right after 10 mins. I got stuck.
I created a SPFx with React framework and installed the @pnp/sp. Then in an onInit() method I set the context (in the root webpart.ts):
public onInit(): Promise<void> {
return super.onInit().then(_=> {
sp.setup({
spfxContext: this.context
});
});
}
public render(): void {
const element: React.ReactElement<IReadReactProps > = React.createElement(
ReadReact,
{
description: this.properties.description,
pageContext: this.context.pageContext
}
);
ReactDom.render(element, this.domElement);
}
But now I don't fin the way to pass the context prop to my component.
I don't even know if the right way to use pnp.
Has anyone a simple sample using SPFx + React + @pnp/sp to get me in the right path? or a link with a sample?
Best regards
Americo
Dec 21 2018 10:04 AM
SolutionDec 22 2018 10:08 AM
Thanks Joel!
This is exactly what I need to get started, is perfect!
Why people doesn't make more samples like this for us that need a little push to get started?
Anyways, thanks a lot!!
Merry christmas and an happy new year!!
/Americo
Dec 22 2018 11:24 AM
Dec 21 2018 10:04 AM
Solution