简体   繁体   English

TypeError:无法在反应 JS 中读取未定义的属性(读取“地图”)

[英]TypeError: Cannot read properties of undefined (reading 'map') in react JS

TypeError: Cannot read properties of undefined (reading 'map') in react JS TypeError:无法在反应 JS 中读取未定义的属性(读取“地图”)

 render() {
    return (
        <div className="container my-3">
            <h2 id="swea">News 24/7 - Top '{this.capitalizeFirstletter(this.props.category)}' Headlines </h2>

            {this.state.loading && <Spinner />}

            <div className='rows'>
                {!this.state.loading && this.state.article.map((element) => {
                    return <div className="col-md-4" key={element.url}>
                        <NewsItem title={element.title ? element.title.slice(0, 90) : ""} description={element.description ? element.description.slice(0, 50) : ""} imageUrl={element.urlToImage} newsUrl={element.url} author={element.author} date={element.publishedAt} source={element.source.name} />
                    </div>
                })}
            </div>

            <div className="container d-flex justify-content-between">
                <button type="button" disabled={this.state.page <= 1} className="btn btn-dark" onClick={this.handlePrevClick} >&larr; Previous</button>
                <button type="button" disabled={this.state.page + 1 > Math.ceil(this.state.totalResults / this.props.pageSize)} id="xxx" className="btn btn-info" onClick={this.handleNextClick} >Next &rarr;</button>
            </div>

        </div>
    );
}

} }

Here's the error *这是错误*

Before mapping over this.state.article first check if the state variable is empty.在映射 this.state.article 之前,首先检查 state 变量是否为空。 For example:例如:

this.state.article.length?this.state.article.map((item)=>{return item}):null;

Just like cyber said, I was getting through the problem for almost an hour and finally I found the problem is empty variable.就像cyber说的,我解决了这个问题将近一个小时,最后我发现问题是空变量。 I didn't return the result and made my array empty, then I continue get "Cannot read properties of undefined (reading 'map')".Please check your variable.我没有返回结果并使我的数组为空,然后我继续得到“无法读取未定义的属性(读取'map')”。请检查您的变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法读取未定义的属性(读取“地图”)React JS - TypeError: Cannot read properties of undefined (reading 'map') React JS 反应:类型错误:无法读取未定义的属性(读取“地图”) - React: TypeError: Cannot read properties of undefined (reading 'map') 未捕获的类型错误:无法读取未定义的属性(读取“地图”)反应 - Uncaught TypeError: Cannot read properties of undefined (reading 'map') React TypeError:无法在反应中读取未定义(读取“地图”)的属性 - TypeError: Cannot read properties of undefined (reading 'map') in react TypeError:无法读取未定义的属性(读取“地图”)反应 - TypeError: Cannot read properties of undefined (reading 'map') react TypeError:无法在 React-Views 中读取未定义的属性(读取“地图”) - TypeError: Cannot read properties of undefined (reading 'map') in React-Views React-Redux - 类型错误:无法读取未定义的属性(读取“地图”) - React-Redux - TypeError: Cannot read properties of undefined (reading 'map') react-refresh-runtime.development.js:315 Uncaught TypeError: Cannot read properties of undefined (reading 'map') - react-refresh-runtime.development.js:315 Uncaught TypeError: Cannot read properties of undefined (reading 'map') 我该如何解决这个问题? 类型错误:无法读取 react.js 中未定义(读取“地图”)的属性 - How can i solve this issue ? TypeError: Cannot read properties of undefined (reading 'map') in react.js TypeError:无法读取未定义的属性(读取&#39;noticeNo&#39;)React.js - TypeError: Cannot read properties of undefined (reading 'noticeNo') React.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM