注意:我已经看过类似的问题;提供的解决方案不能解决我的问题。
我的 React 应用程序出现以下错误
TasksColumn(...):渲染没有返回任何内容。这通常 > 意味着缺少 return 语句。或者,不渲染任何内容,返回 >null。
这是相关的代码:
TasksColumn.js
import React, { Component } from "react";
import { render } from "react-dom";
import { Col, Row } from "react-bootstrap";
const taskData = [
{
title: "Preliminary Report",
course: "Capstone Design",
type: "Report",
deadline: "2019-10-04"
},
{
title: "title2",
course: "course2",
type: "type2",
deadline: "date2"
},
{
title: "title3",
course: "course3",
type: "type3",
deadline: "deadline3"
}
];
const TaskRecord = ({ title, course, type, deadline }) => {
return (
<Row class="task-record">
<Col>
<div class="task-record-title">
<h5>{title}</h5>
</div>
<div class="task-record-course">
<h6>{course}</h6>
</div>
</Col>
<Col>
<div class="task-record-type">
<p>{type}</p>
</div>
<div class="task-record-deadline">
<p>{deadline}</p>
</div>
</Col>
</Row>
);
};
export default class TasksColumn extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: false,
mounted: false,
data: []
};
}
componentDidMount() {
this.setState({
isLoading: true,
mounted: true
});
}
render() {
const { tasks } = this.props;
let mounted = this.state.mounted;
if (mounted == true) {
return (
<Col id="tasks-column">
{tasks.map((task, i) => (
<TaskRecord
key={i}
title={task.title}
course={task.course}
type={task.type}
deadline={task.deadline}
/>
))}
</Col>
);
}
}
}
render(<TasksColumn tasks={taskData} />, document.querySelector("#root"));
Dashboard.js
import React from "react";
import { Container, Row, Col } from "reactstrap";
import TasksColumn from "../../molecules/TasksColumn";
export default function Dashboard(props) {
return (
<React.Fragment>
<Container>
<Row>
<TasksColumn />
</Row>
</Container>
</React.Fragment>
);
}
作为一个最终的结果,我需要TasksColumns
在Dashboard.js
渲染每个taskData
里面TaskRecord
。