Top level 'this' expression

Webstorm 2019.1.1, React. After the last update I receive this message which should not appear

Reports this expressions occurring outside of object literals or constructor bodies. Such this expressions are legal JavaScript, and reference the top-level "global" JavaScript object, but are largely useless.

5 comments

To provide some more detail: I see it in the render function here:

export default class Test extends React.Component {
constructor ( props ) {
super(props);

this.state = { data : props.data}
}

render() {
return <div>{this.state.data}</div>;
}
}

This should not be highlighted as a top level this, because it is bound to the instance the render method is invoked on.

1

Please sign in to leave a comment.