Search code examples
react-nativeimporterror-handlingexportimporterror

Can we import the component with different name in React Native


I have imported the component of Name StoryBook that is exported default name.

But is also works as StoryBookX.

e.g

import StoryBook from 'storybook', // This is default name. import StoryBookX from 'storybook, //This is not default name but it also work.

Can anybody explain that what the reason of it.

<View>
<StoryBook />
</View>



<View>
<StoryBookX />
</View>

Both are wokring while there is no default component of name StoryBookX

I tried it .Because i was expecting that this will not work.But it works.


Solution

  • yes. if we have a component Like

    import React from 'react';
    import {View} from 'react-native';
    const AdView = () => {
      return <View></View>;
    };
    
    export default AdView;
    

    then we can export it with different names like this,

    import AdView from "./AdView"
    import CustomAdView from "./AdView"
    import MyAdView from "./AdView"
    import YourAdView from "./AdView"