[英]How can I render a list of search results?
I'm really stumped as to what is going on.我真的很困惑到底发生了什么。 I reviewed videos on map, arrow functions and implicit returns but still have no idea why my code is not making sense.我查看了有关 map、箭头函数和隐式返回的视频,但仍然不知道为什么我的代码没有意义。 When I console log everything it is fine, all the data is there.当我控制台记录一切正常时,所有数据都在那里。 However, when I try to output the data into a div or list, nothing renders.但是,当我尝试将 output 数据放入 div 或列表时,没有任何渲染。 What gives?是什么赋予了?
Here is the code in question:这是有问题的代码:
const renderSearchResults = () => {
if (this.state.searchResults) {
Object.keys(this.state.searchResults).map((key) => {
console.log(this.state.searchResults[key]);
return <div>{this.state.searchResults[key].Title}</div>;
});
} else {
return <p>Loading...</p>;
}
};
Object.keys(this.state.searchResults).map()
creates a new array but you need to return it in your renderSearchResults()
Object.keys(this.state.searchResults).map()
创建一个新数组,但您需要在renderSearchResults()
中返回它
return Object.keys(this.state.searchResults).map((key) => {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.