reactjs – React:export const export default vs export default

前端之家收集整理的这篇文章主要介绍了reactjs – React:export const export default vs export default前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我通过“双”导出遇到了当前的组件创建.你能解释一下它是否有真正的用途,或者只是作者的偏好?
import React from 'react'
import DuckImage from '../assets/Duck.jpg'
import './HomeView.scss'

export const HomeView = () => (
  <div>
    <h4>Welcome!</h4>
    <img
      alt='This is a duck,because Redux!'
      className='duck'
      src={DuckImage} />
  </div>
)

export default HomeView

P.S:当前代码稍后由webpack2捆绑.

在这种情况下,两个导出导出相同的东西.
import Homeview

import { Homeview }

会给你相同的模块(HomeView组件).

不过,我看到你正在使用Redux.如果你正在做类似的事情

export const HomeView ...

export default connect(mapStateToProps)(HomeView);

这可能很有用,因为您可能希望有时使用非Redux连接的组件,或者您可能需要它来进行测试.

原文链接:https://www.f2er.com/react/301094.html

猜你在找的React相关文章