【发布时间】:2019-10-01 09:01:43
【问题描述】:
- 我需要通过
searchbar组件将搜索值传递给menubar组件以进行自定义搜索 - 所以我从代码沙箱中取出一个现有的功能组件并转换为类组件。
- 但我收到一个错误
App(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null. - 我正在尝试通过
componentWillRecieveProps实现 - 你能告诉我如何解决它吗?
- 在下面提供我的代码 sn-p 和沙箱。
https://codesandbox.io/s/eloquent-galileo-14874
class App extends Component {
state = {
groupCheckBoxValues: [],
groupRadioValue: "PRO"
};
componentWillReceiveProps({ search }) {
console.log(search);
}
componentDidMount() {
this.fetchdata("story");
}
fetchdata(type = "", search_tag = "") {
var url = "https://hn.algolia.com/api/v1/search?tags=";
fetch(`${url}${type}&query=${search_tag}`)
.then(res => res.json())
.then(data => {
this.props.getData(data.hits);
});
}
render() {
<div> testing</div>;
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
【问题讨论】:
-
正如错误消息明确暗示的那样,您在
render方法中缺少return。只需return (<div>testing</div);
标签: javascript html css reactjs redux