1

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

enter image description here

Have you any solution ?

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

1 Answer 1

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
  • 1
    @Chandresh if the solution is helpful, please accept the answer. Thanks Jan 10, 2019 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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