React: const export + default export vs default export

I was faced with creating the current component with a "double" export. Could you explain if this is really used, or is it just the author’s preference?

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 

PS: the current code is later linked to webpack2.

+6
source share
1 answer

In this case, both exports export the same thing. Both

 import Homeview 

and

 import { Homeview } 

You will get the same module (HomeView component).

I see that you are using Redux. If you were doing something like

 export const HomeView ... export default connect(mapStateToProps)(HomeView); 

This can be useful in that you can sometimes use a component that is not connected to Redux, or you may need it for testing.

+11
source

Source: https://habr.com/ru/post/1015110/


All Articles