Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some help with JS Import statements #39

Closed
moschap opened this issue Apr 16, 2016 · 7 comments
Closed

Some help with JS Import statements #39

moschap opened this issue Apr 16, 2016 · 7 comments

Comments

@moschap
Copy link

moschap commented Apr 16, 2016

Good day Guys,

Sorry for asking if this is obvious but where is GitterMobile defined from this statement import GitterMobile from './app', in the index.android.js file.

I have looked in the app /folder which is in the root of the project and i still don't see it. Please help and great job too.

@terrysahaidak
Copy link
Contributor

Hey @moschap, thank for the kind words.

import GitterMobile from './app' is just the short of import GitterMobile from './app/index.js'.
You can check the index.js file.

@moschap
Copy link
Author

moschap commented Apr 18, 2016

Thanks @terrysahaidak ,
I guessed as much that was what the intent was, but my confusion is that in the file /app/index.js there is only this line of export, export default Root.

Sorry again if i am asking as obvious question but where is the GitterMobile derived from? or if there are links that you can refer me to, to catch up on the pattern of import.

@terrysahaidak
Copy link
Contributor

terrysahaidak commented Apr 18, 2016

As you can see, it's not just export default Root

class Root extends Component {
  render() {
    return (
      <Provider store={store}>
        <View style={{flex: 1}}>
          <App />
        </View>
      </Provider>
    )
  }
}

export default Root

It exports Component named Root I defined above.
I could also write export default class Root extends Component { }.
It all is just a new module syntax, with old one I have to write:
module.exports = Root.

@moschap
Copy link
Author

moschap commented Apr 18, 2016

Yes that is correct. Sorry i missed out that part of the code in my earlier question. I understand that part actually.
The part that is confusing me is the GitterMobile in the import statement. I would have assumed that based on the code above the import from index.android.js file would have been import Root from './app'

@terrysahaidak
Copy link
Contributor

terrysahaidak commented Apr 18, 2016

Yeah, but it default export, not named, so I can name the module var whatever I want:

// foo.js
const foo = { }
export default foo

// bar.js
const bar = { }
export bar

// baz.js
import whatEverIwant from './foo' // const someVar = require('./foo')
import {bar} from './bar' // const bar = require('./bar').bar or const {bar} = require('./bar')

So I named my root component in the entry file as GitterMobile for better semantic :)

@moschap
Copy link
Author

moschap commented Apr 18, 2016

@terrysahaidak ,

Oh now i understand. Thanks a bunch for the clarification, it all makes sense now.

@moschap moschap closed this as completed Apr 18, 2016
@terrysahaidak
Copy link
Contributor

terrysahaidak commented Apr 18, 2016

I glad I could help you, @moschap :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants