我无法访问函数内的类变量,以下是我的代码:
export class MyClass extends React.Component<{}, {}>{
public myArray: string[]; //I want to access this variable
constructor() {
this.state = { name: "" }
}
private _hello = () => {
console.log(this.state.name);
console.log(this.myArray) //this lines throws undefined
}
render(){
<button onClick={this._hello}>Click</button>
}
}