skip to Main Content

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.

2

Answers


  1. When you export component as default then you can import it by different name also.

    Login or Signup to reply.
  2. 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"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search