I have a boolean value that I want to update on a button click. Looking at the console.log() that I put in, I can see that the value does change as I expect it to, but the value doesn’t change on the front end in the webpart. It stays at the default “true” value. How do I get the value on the front end to change, based on what the state of the boolean is?
import { Version } from '@microsoft/sp-core-library';
import { BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField } from '@microsoft/sp-webpart-base';
import styles from './LoginWireTestWebPart.module.scss';
import * as strings from 'GetlistofalllistsWebPartStrings';
export interface ITesting {
clickHandler : () => void
}
export interface ILoginWireTestWebPartProps {
}
function log (){
console.log("before -->", testBool)
testBool = !testBool
console.log("after -->", testBool)
}
var testBool : boolean = true;
export default class LoginWireTestWebPart extends BaseClientSideWebPart<ILoginWireTestWebPartProps> {
public render(): void {
this.domElement.innerHTML = `
<button class="btn btn-success" id="testingButton" > <h1> TESTING </h1> </button>
<br>
<br>
${testBool}
<div class="${ styles.loginWireTest }"></div>
`;
this._setButtonEventHandler();
}
protected onInit(): Promise<void> {
return super.onInit();
}
private _setButtonEventHandler() : void {
this.domElement.querySelector('#testingButton')?.addEventListener('click', () => {
log()
})
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel,
})
]
}
]
}
]
};
}
}
New contributor
Shae Montague is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.