简体   繁体   English

React Component Array Map-渲染未返回任何内容。 这通常意味着缺少return语句。 或者,不渲染任何内容,则返回null

[英]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.

相关问题 Home(…):渲染未返回任何内容。 这通常意味着缺少return语句。 或者,不渲染任何内容,则返回null - Home(…): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null 错误:渲染没有返回任何内容。 这通常意味着缺少 return 语句。 或者,不渲染任何内容,返回 null - Error: Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null unboundStoryFn(…):渲染没有返回任何内容。 这通常意味着缺少 return 语句。 或者,什么也不渲染,返回 null - unboundStoryFn(…): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null 反应错误:渲染没有返回任何内容。 这通常意味着缺少 return 语句。 或者,什么也不渲染,返回 null - React Error: Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null React - 错误:应用程序(...):渲染没有返回任何内容。 这通常意味着缺少返回语句。 或者,不渲染任何内容,返回 null - React - Error: App(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null 出现此错误的学校项目:渲染未返回任何内容。 这通常意味着缺少 return 语句。 或者,不渲染任何内容,返回 null - School project with this error: Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null 我收到此错误 &gt;&gt; 渲染未返回任何内容。 这通常意味着缺少 return 语句。 或者,不渲染任何内容,返回 null - I got this this error >> Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null 错误:StateProvider(...):渲染没有返回任何内容。 这通常意味着缺少 return 语句。 或者,什么也不渲染,返回 null - Error: StateProvider(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null 错误:聊天(...):渲染没有返回任何内容。 这通常意味着缺少 return 语句。 或者,不渲染任何内容,返回 null - Error: Chats(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null 我该如何解决:“渲染没有返回任何内容。 这通常意味着缺少 return 语句。 或者,什么也不渲染,返回 null。” - How can I solve: “Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM