React: Cannot access index of an array in a state (index undefined)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an array as a state property in my component, like this: this.state = { postData: [{id: 1, author: 'Mary'}, {id:2, author: 'John'}] } When I access it through console.log , such as this.state.postData[0] , it shows the contents of the object and works correctly But when I try to output it as a content of an element, this way: <p>{this.state.postData[0].author}</p> It says that this.state.postData[0] is undefined. I so far have not been able to find out why it happens, is there some special way to access arrays in React? EDIT: