【问题标题】:Why does import operation works in the below react component?为什么导入操作在下面的反应组件中起作用?
【发布时间】:2022-07-17 21:00:10
【问题描述】:

为什么下面的反应有效?由于 Hello.js 组件中的函数名称是 Hello 但在引入 Hello.js 的主组件中没有提及,是箭头函数的属性吗?

Hello.js 组件:

import React from 'react';
const Hello =() => <h1> HELLO <h1/>
export default hello

Hello.js 组件在哪里被导出/被调用。

import React from 'react';
import MyComponent form './Hello'
class App extends React.Component{
   render(){
     return(
            <div>
               <MyComponent />
            <div/>
           );
      }
 }

【问题讨论】:

  • 你的代码中有很多错别字。 helloHello 不同,formfrom 不同。

标签: javascript react-component rect


【解决方案1】:

这个叫做default导出,你可以在导入的时候随意命名组件。

【讨论】:

    猜你喜欢
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 2018-07-31
    • 1970-01-01
    • 2014-12-18
    • 2018-07-12
    • 1970-01-01
    相关资源
    最近更新 更多