首页 > 解决方案 > 我有这个问题,尽管没有更改 create-react-app 上的任何配置,但我的反应组件没有呈现

问题描述

我假设它与 create-react-app 更新有关。通常在我以前的项目中,当检查页面时,我会看到每个组件都分解为它的 html 标签,但现在它只显示组件的名称,而组成组件的标签不会显示。

//App.js
import React from 'react';
import logo from './logo.svg';
import './App.css';
import heading from './head';

function App() {
  return (
    <div>
        <heading/>
    </div>
  );
}

export default App;
//head.js
import React from 'react';

const head = () => {
    return (
        <h1>hello</h1>
    )
}

export default head;

此代码在不更改 create-react-app 配置的情况下仍会显示空白页输出

标签: reactjscreate-react-app

解决方案


组件名称必须以大写开头:

// rest of imports ...
import Heading from './head';

function App() {
  return (
    <div>
        <Heading/>
    </div>
  );
}

export default App; 

推荐阅读