Reactjs 数据未在屏幕上填充,请作出反应
我正在使用react中的类组件,它以数组的形式接收数据,该类的总线数据不会显示在屏幕上Reactjs 数据未在屏幕上填充,请作出反应,reactjs,Reactjs,我正在使用react中的类组件,它以数组的形式接收数据,该类的总线数据不会显示在屏幕上 import React, { Component } from 'react'; import PropTypes from 'prop-types'; class CountryList extends Component { constructor(props) { super(props); } renderCountry = country => { conso
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class CountryList extends Component {
constructor(props) {
super(props);
}
renderCountry = country => {
console.log(country);
return `<ol>${country} ${country.substring(0, 15)}</ol>`;
};
render() {
const { countryData } = this.props;
return (
<div className="col-xs-12 col-sm-12 col-md-12 col-lg-12">
{countryData.map(country => {
this.renderCountry(country);
})}
</div>
);
}
}
CountryList.propTypes = {
countryData: PropTypes.arrayOf(PropTypes.string),
};
export default CountryList;
import React,{Component}来自'React';
从“道具类型”导入道具类型;
类CountryList扩展了组件{
建造师(道具){
超级(道具);
}
renderCountry=国家=>{
控制台日志(国家);
返回`${country}${country.substring(0,15)}`;
};
render(){
const{countryData}=this.props;
返回(
{countryData.map(国家=>{
这个国家(国家);
})}
);
}
}
CountryList.propTypes={
countryData:PropTypes.arrayOf(PropTypes.string),
};
导出默认国家列表;
我做错了什么?您在
地图中缺少返回:
return (
<div className="col-xs-12 col-sm-12 col-md-12 col-lg-12">
{countryData.map(country => {
return this.renderCountry(country); // add return here
})}
</div>
);
返回(
{countryData.map(国家=>{
return this.renderCountry(country);//在此处添加return
})}
);
或<代码>{countryData.map(country=>(this.renderCountry(country);))}