Forum Discussion
Unable to pass data from React component to webpart ts file
I have been unable to pass data from a react component back to the webpart ts using a function passed into props. I created the simplest example of this and continue to get the following error:
TypeError: Cannot read property 'props' of undefined
Here is my webpart files
ISync1Props.ts
Ok solved it by looking at this article:
https://www.voitanos.io/blog/deal-with-undefined-this-react-event-handler-performant-way/
added a bind statement in the constructor of the react component so that the passData function has proper reference to "this".
constructor(props: ISync1Props) {super(props);this.passData = this.passData.bind(this);}
- jay chadwellCopper Contributor
Ok solved it by looking at this article:
https://www.voitanos.io/blog/deal-with-undefined-this-react-event-handler-performant-way/
added a bind statement in the constructor of the react component so that the passData function has proper reference to "this".
constructor(props: ISync1Props) {super(props);this.passData = this.passData.bind(this);}