【问题标题】:Getting Error while adding a component to App component of React将组件添加到 React 的 App 组件时出现错误
【发布时间】:2021-02-17 04:06:16
【问题描述】:
import React, {Component} from 'react'


const Greet=()=>  <h1>Say helllo</h1>


export default Greet;

我在 App.js 中创建并导入的这个功能组件

    import logo from './logo.svg';
    import './App.css';
    import './Components/Greet'

    function App() {
    return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
        <br></br>
        <button>Submit</button>
      </header>
      <Greet/>
    </div>
  );
}

export default App;

但在 chrome web 中出现错误

**src\App.js 第 24:8 行:“问候”未定义 react/jsx-no-undef

src\Components\Greet.js 第 7:16 行:“问候”未定义 no-undef**

React 新手如果有人可以帮助我,很有帮助。

【问题讨论】:

  • src 文件夹 Components 文件夹中 Greet.js

标签: reactjs


【解决方案1】:
const greet=()=>  <h1>Say helllo</h1>

尝试Greet 而不是greet

在你的App.js中也这样写

import Greet from "./Components/Greet";

【讨论】:

  • 感谢您的回复,但在任何地方更改为 Greet 后还是一样,您能帮我解决一下吗?
  • 请编辑您的问题并发布您尝试过的新代码。我会再试一次。
  • 你能帮我解决这个问题吗
猜你喜欢
  • 2021-03-28
  • 2019-02-16
  • 2016-07-03
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-30
相关资源
最近更新 更多