One thing to be aware of, is that when you write:
class BottomPanel extends React.Component<Props, {}> {
dropDownUpdate = e => this.setState({ dropDownValue: e.currentTarget.textContent });
}
This (currently) is not valid ES6 syntax. You can't assign a class variable with an equals sign that way. The reason it works is because of the transform-class-properties
babel plugin, more on that below.
See this question and answer for more details:
ES6 class variable alternatives
Technically, the right way to declare a class variable is with the this
keyword like:
class BottomPanel extends React.Component<Props, {}> {
constructor(props) {
this.dropDownUpdate = this.dropDownUpdate.bind(this)
}
dropDownUpdate(e) {
this.setState({ dropDownValue: e.currentTarget.textContent });
}
}
For why you can't just do:
class BottomPanel extends React.Component<Props, {}> {
constructor(props) {
this.dropDownUpdate =e => this.setState({ dropDownValue: e.currentTarget.textContent });
}
}
see this post: Can I use arrow function in constructor of a react component?
Now the thing is - I assume that you are using Create React App - which comes with the transform-class-properties
babel plugin - which is why that first declaration works.
Take a look at this question as to why you would want to to the this.dropDownUpdate = this.dropDownUpdate.bind(this);
trick. It's not necessary - but you run into a debugger issue (the browser not being aware of the transform-class-properties
babel transform).
Chrome, Firefox debuggers not displaying the correct value for 'this' in a react app
Otherwise you can just clear your class methods like:
class BottomPanel extends React.Component<Props, {}> {
dropDownUpdate = e => this.setState({ dropDownValue: e.currentTarget.textContent });
}