0

I'm making app with using React Native. I noticed strange thing.

This code got me error unless I change last sentence to

export default MyButton3;

I want to export more than one pure components per file. I can do that if I don't use pure component declare.

But Why I can't do that with pure Components?

Thanks.

const MyButton3 = (props) => (
    <TouchableOpacity style={[props.style,{height:40, backgroundColor:Asset.color_skyblue, justifyContent:'center'}]} onPress={props.onPress}>
        <Text style={{color:'white', alignSelf:'center', fontSize:20, fontWeight:'bold'}}>{props.title}</Text>
    </TouchableOpacity>
);

export MyButton3;
Bright Lee
  • 2,306
  • 2
  • 27
  • 55
  • I guess this explain my question. https://stackoverflow.com/questions/31852933/why-es6-react-component-works-only-with-export-default – Bright Lee Dec 15 '17 at 19:00
  • Possible duplicate of [Why es6 react component works only with "export default"?](https://stackoverflow.com/questions/31852933/why-es6-react-component-works-only-with-export-default) – Charlie Martin Dec 15 '17 at 19:04

1 Answers1

3

You can. Your question is more about the syntax on how to export multiple functions in one file. You have 2 syntax choices:

const a = 1
const b = 2
export { a, b }

or

export const a = 1
export const b = 1

Then to import to a file

import { a, b } from 'some directory'
Andrew
  • 7,201
  • 5
  • 25
  • 34