1

Hear is a SPFx react webpart ".tsx" file code image

enter image description here

Have you any solution ?

  • modify it to {this.showDialog.bind(this)} and check ? – Gautam Sheth Jan 10 at 10:42
  • 1
    @GautamSheth This is not recommended due to performance reasons and tslint in SPFX solution won't even allow it. – Lukas Nespor Jan 10 at 10:51
3

You have to use arrow function in this.state.items.map this in anonymous function has different context and you would have to bind also the anonymous function itself like:

this.state.items.map(function (item, key) {
    return (
        <div>
            <button onClick={this.showDialog}>click</button>
        </div >
    );
}.bind(this));

Correct use:

this.state.items.map((item, key) => 
    <div>
        <button onClick={this.showDialog}>click</button>
    </div>
);
  • 1
    @Chandresh if the solution is helpful, please accept the answer. Thanks – Lukas Nespor Jan 10 at 11:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.