JSX syntax error on PHPStorm

I am trying to conditionally set a property in a set of elements.

render: { var buttons = []; for (var i = 1; i <= this.props.totalWeeks; i++) { buttons.push( <button onClick={ this.changeWeek.bind(this, i) } disabled={ i === this.state.currWeek }>{ i } </button>); } } 

Everything works fine in the browser. But PHPStorm (version 8.0.3) marks the expression { i === this.state.currWeek } as an error for the value of an invalid attribute .

I tried to change this by calling a function, variable, etc., but it can't seem to make a mistake. I also tried to disable this validation rule on PHPStorm, but I can not find the parameter that would disable it.

Question

How can I make this error in PHPStorm? If this is a mistake, then how can I get rid of it by conditionally adding HTML attributes to a group of elements in some other way?

+5
source share
1 answer

1) If it is to edit the reaction (and not the user-defined function), it should be "render () {return;}" against your code

This is a 100% syntax error, the browser ignores it because it should, if you use it in the definition definition class, the following syntax:

 class Test { objectExample: { some: "value" } functionExample() { return someExecutionCode(); } lambdaFunctionExample = () => { return someExecutionCode(); } } 

But you mix the 1st and 2nd lines at the same time, start as the definition of an object, with the body as a function that do not fit together.

2) Your rendering function does NOT return anything, it does an array, but does not return it.

0
source

All Articles