1 回答
TA贡献1993条经验 获得超5个赞
根据评论和 stackblitz 链接,问题是您没有从函数内部返回值
import React, { Component } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';
class ClassRoomUnit extends Component{
displayName;
classID;
render() {
return(
<div>
{this.props.displayName}
{this.props.classID}
</div>
);
}
}
class App extends Component {
state={
c:[1,2,3]
}
classRoom(classRooms)
{
console.log(classRooms);
if(classRooms!==null)
{
const updatedClass = classRooms.map((classRoom)=>{
return <ClassRoomUnit displayName={"as"} classID={"asdsa"} />;
});
}
return updatedClass;
}
render() {
return (
<div>
dynamic list start
{this.classRoom(this.state.c)}
dynamic list end
</div>
);
}
}
render(<App />, document.getElementById('root'));
添加回答
举报