gpt4 book ai didi

javascript - 你好,世界不使用 React js 中的功能组件进行打印

转载 作者:行者123 更新时间:2023-12-01 00:34:19 31 4
gpt4 key购买 nike

我正在尝试使用 React js 在本地主机上打印 Hello World。但每当我运行代码时,浏览器页面总是空白。

***App.js***

import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import greet from './components/Greet'

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

export default App;



***Greet.js***
import React from 'react'
/* Greet(){
return <h1>Hello, Neha</h1>
}*/
const Greet = () =><h1>Hello, Neha</h1>

export default Greet;

我已在 src 文件夹中添加了 Greet 组件,即 src 文件夹 -> 组件文件夹 -> Greet.js

我在终端上收到的错误是:-

Failed to compile.

./src/App.js
Line 10:8: 'Greet' is not defined react/jsx-no-undef

Search for the keywords to learn more about each error.

最佳答案

从 './components/Greet' 导入 Greet 更改为 从 './components/Greet' 导入 Greet

关于javascript - 你好,世界不使用 React js 中的功能组件进行打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58260320/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com