Reactjs:渲染一无所获

时间:2018-08-06 07:34:24

标签: reactjs react-dom

我已经使用create-react-app设置了一个基本的React应用,并创建了我的第一个组件。但是,由于浏览器窗口中的此错误,该项目无法生成或呈现:

CountDown(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.
./src/index.js
D:/ReactDev/CountDownReact/countdown/src/index.js:8

这是我的index.js文件代码:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import Bulma from 'bulma/css/bulma.css'
import App from './components/App/App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

和我导入新组件的App.js

import React, {Component} from 'react';
import './App.css';
import CountDown from '../countdown/Countdown';

class App extends Component {
    render() {
        return(
            <div className="App">
                Hello React
                <CountDown/>
            </div>
        );
    }
}

export default App;

最后,我的Countdown组件代码:

import React from 'react';

const CountDown = (props) => {
    <section class="section">
        <div className="hero-body">
            <div class="container">
                <h1 class="title">Section</h1>
                <h2 class="subtitle">
                 A simple container to divide your page into <strong>sections</strong>, like the one you're currently
                reading
                </h2>
            </div>
        </div>
    </section>
};
export default CountDown;

我还需要在这里导入我的新组件吗?我该如何解决这个问题。谢谢。

3 个答案:

答案 0 :(得分:5)

您的倒数组件不返回任何内容,您可以将awk '{$0=gensub(/ +([0-9])/, ":\\1", "g", $0); print gensub(/([0-9]) +/, "\\1:", "g", $0)}' ip.txt 替换为{}以便返回。

()

应该这样做。

答案 1 :(得分:1)

CountDown组件不返回JSX。您可以添加显式return语句以返回JSX。

答案 2 :(得分:0)

有同样的问题:

<块引用>
function Input(props) {
return 
<input type={props.type} placeholder={props.placeholder} />
 }

相反,它必须是:

<块引用>
function Input(props) {
return <input type={props.type} placeholder={props.placeholder} />
 }