[英]export error when loading basic react application
i am learning react.我正在学习反应。 but my basic sample is not working.
但我的基本样本不起作用。 my app.js file is like below
我的 app.js 文件如下
import React, { Component} from 'react';
import './App.css';
import { Greet } from './components/Greet';
class App extends Component {
render() {
return <div className="App">
<Greet></Greet>
</div>
}
}
export default App;
my component file is like below我的组件文件如下
import React from 'react';
function Greet(){
return <h1>Test</h1>
}
when i load my application, error said Attempted import error: 'Greet' is not exported from './components/Greet'.
当我加载我的应用程序时,错误提示
Attempted import error: 'Greet' is not exported from './components/Greet'.
What is this error.这是什么错误。 how i fix ?
我怎么修?
import React from 'react';
export function Greet(){
return <h1>Test</h1>
}
You forgot to export the Greet component.您忘记导出 Greet 组件。
Just add export before function Greet()
:只需在
function Greet()
之前添加 export :
import React from 'react';
export function Greet(){
return <h1>Test</h1>
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.