This map
callback:
let space = _.map(this.state.space, (space, id) => {
<SpaceFilterResults
key = {id}
space={space}
propertyType={this.state.propertyType}
rooms={this.state.rooms}
/>
});
will not return anything.
Here is another example that doesn’t work:
let nums = [1, 2, 3].map(x => { x * 2 })
If an arrow function body is a block, it doesn’t implicitly return anything.
// { x * 2; } is a block so this doesn’t work
let nums = [1, 2, 3].map(x => { x * 2; })
// x * 2 is an expression so this works
let nums = [1, 2, 3].map(x => x * 2)
If you use {
and }
inside an arrow function, you must also use a return
statement:
// { x * 2 } is a block with a return so this works
let nums = [1, 2, 3].map(x => { return x * 2; })
So to fix your code, either make the arrow function body an expression by removing {
and }
:
let space = _.map(this.state.space, (space, id) =>
<SpaceFilterResults
key = {id}
space={space}
propertyType={this.state.propertyType}
rooms={this.state.rooms}
/>
);
or keep it as a block but add an explicit return
statement:
let space = _.map(this.state.space, (space, id) => {
return (
<SpaceFilterResults
key = {id}
space={space}
propertyType={this.state.propertyType}
rooms={this.state.rooms}
/>
);
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…