渲染未返回任何内容.这通常意味着缺少return语句.或者,不渲染任何内容,则返回null [英] Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null

查看:85
本文介绍了渲染未返回任何内容.这通常意味着缺少return语句.或者,不渲染任何内容,则返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在React中有一个要导入index.js的组件,但是它给出了这个错误:

I have a component in React which I am importing in index.js, but it is giving this error:

渲染未返回任何内容.这通常意味着缺少return语句.或者,要不显示任何内容,请返回null

Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null

index.js:

import React from 'react';
import ReactDOM from 'react-dom'; 
import  Search_Bar from './components/search_bar';

const   API_KEY = 'AIzaSyCnpDObOLiiqN87YKJKZ-cxzdAsvYD1F-U';

const App = () => {
    return
    (
        <div>
            <Search_Bar />
         </div>
    );
}

ReactDOM.render(<App />, document.querySelector('#root'));

组件:

import React from 'react';

const Search_Bar = () =>
{
    return <input />;
};

export default Search_Bar;

推荐答案

我在 render()方法中遇到了同样的问题.当您从 render()返回时,问题就来了:

I had same problem in the render() method. The problem comes when you return from render() as :

render() {
    return 
    (
        <div>Here comes JSX !</div>
    );
}

即如果您在新行中插入括号

尝试使用:

render() {
    return (
        <div>Here comes JSX !</div>
    );
}

这将解决错误

这篇关于渲染未返回任何内容.这通常意味着缺少return语句.或者,不渲染任何内容,则返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆