问题
Based on the solution of my question: setState fires and render method gets hit, but nothing rerenders
Code works if there is NO newline between return
and the (
, and fails otherwise.
Example:
this works:
render()
{
return (
<View >
<ListView dataSource={this.state.beers_ds} renderRow={renderRow.bind(this)} />
</View>
);
}
But this fails:
render()
{
return
(
<View >
<ListView dataSource={this.state.beers_ds} renderRow={renderRow.bind(this)} />
</View>
);
}
Why?
回答1:
Seems like Automatic Semicolon Insertion might be biting you in the butt. I believe javascript will insert a ;
at the end of a return
statement automatically.
Why doesn't a Javascript return statement work when the return value is on a new line?
回答2:
As answered here: Javascript function fails to return object when there is a line-break between the return statement and the object?
it's just a matter of JS syntax. Semicolons are automatically added and thus the compiler treats
return
( sth )
as
return;
( sth )
来源:https://stackoverflow.com/questions/46309513/why-a-newline-between-return-and-breaks-the-code