Forum Discussion
SPFx + PnP: how do I get web part property values inside the .then() ?
- Are you using react?
- Is this in a .ts file or a .tsx component?
- How are you setting the questionClass property and what are you using it for?
As a first step, assuming you're working at the root of your web part (webPartNameWebPart.ts) your properties will be undefined by default when you load the web part, you should set default values for your property pane properties in the manifest.json for the web part see an example of manifest.json below:
{
"$schema": "../../../node_modules/@microsoft/sp-module-interfaces/lib/manifestSchemas/jsonSchemas/clientSideComponentManifestSchema.json",
"id": "You'reID",
"alias": "HelloWorldWebPart",
"componentType": "WebPart",
"version": "*",
"manifestVersion": 2,
"requiresCustomScript": false,
"preconfiguredEntries": [
{
"groupId": "You'reGroupID",
"group": {
"default": "Under Development"
},
"title": {
"default": "hellow World"
},
"description": {
"default": "This is the defualt description"
},
"officeFabricIconFontName": "Page",
//Below is where you set the property defaults, you need to have one for each of the properties you have setup. If you have an array that isn't defined here (even though it's blank) it will be undefined at runtime
"properties": {
"descripton": "description text",
"booleanProperty": true,
"arrayProperty": [],
"numberProperty": 0,
}
}
]
}There is some more about preconfiguredEntries here: http://sharepointseb.co.uk/2017/08/17/updating-preconfiguredentries/
Thanks for the response. I learned about this late last week from a MS guy over at the dev docs site: https://github.com/SharePoint/sp-dev-docs/issues/759
I've basically taken them to task for this silly kludge; if you define the properties in the property pane configuration (after all, the name implies you are configuring the properties!), I feel strongly that you shouldn't have to do it again in the manifest. Why have an option in there to set a default value if it will just be ignored? We shouldn't have to define the same thing twice.
As to your questions:
1. No, no react framework in this project
2. It's in the plain ol' <webpartname>.ts
3. User's putting the web part on the page can use "questionClass" to add class names that they want to use to alter the way the data is displayed. If they've added one or more class names, I want to add those to the rendering at runtime.
I like the tip in your link as well. Thanks again.