[英]React Component Array Map - Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null
I am new to React. 我是React的新手。 I'm putting together a component that will repeat list items based on an array for a set of navigation options.
我正在组合一个组件,该组件将基于数组重复列出项以获取一组导航选项。 I am getting the error: Nothing was returned from render.
我收到错误:渲染未返回任何内容。 This usually means a return statement is missing.
这通常意味着缺少return语句。 Or, to render nothing, return null.
或者,不渲染任何内容,则返回null。
This is my component: 这是我的组件:
import React from 'react';
const navOptions = [
{name: 'Home'},
{name: 'Me Mine and Ours'},
{name: 'Collection'},
{name: 'Yo!'}
];
const Nav = () => {
navOptions.map((name, index) => {
return (
<li className="nav-item">
<a className="nav-link" href="#" key="">j</a>
</li>
)
})
};
export default Nav;
You are missing a return
. 您错过了
return
。 You have to return the result of navOptions.map
as well. 您还必须返回
navOptions.map
的结果。
import React from 'react';
const navOptions = [
{name: 'Home'},
{name: 'Me Mine and Ours'},
{name: 'Collection'},
{name: 'Yo!'}
];
const Nav = () => {
return navOptions.map((name, index) => {
return (
<li className="nav-item">
<a className="nav-link" href="#" key="">j</a>
</li>
)
})
};
export default Nav;
You are missing the main return in this part 您缺少这部分的主要回报
const Nav = () => { navOptions.map((name, index) => { return ( <li className="nav-item"> <a className="nav-link" href="#" key="">j</a> </li> ) }) };
Change to (I think you will need a <div>
to wrap the <li>
s up) 更改为(我想您将需要一个
<div>
来包装<li>
)
return (<div>{navOptions.map(....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.