stormpath-express-react-example icon indicating copy to clipboard operation
stormpath-express-react-example copied to clipboard

Purpose of the index.js file?

Open scheung38 opened this issue 9 years ago • 2 comments

Why do we need this file?

export MasterPage from './MasterPage'
export IndexPage from './IndexPage'
export LoginPage from './LoginPage'
export RegisterPage from './RegisterPage'
export ResetPasswordPage from './ResetPasswordPage'
export VerifyEmailPage from './VerifyEmailPage'
export ProfilePage from './ProfilePage'
export ChangePasswordPage from './ChangePasswordPage'

When each of the, say for example IndexPage has its own

export default class IndexPage extends React.Component { ....
}

scheung38 avatar Oct 07 '16 14:10 scheung38

Did you figure this out? I don't understand what this file does, but without it things fail.

hoff11 avatar Jan 05 '17 18:01 hoff11

@micahstartnow @scheung38 without it, you would have to import each Component as such:

import MasterPage from './MasterPage'
import IndexPage from './IndexPage'
import LoginPage from './LoginPage'
import RegisterPage from './RegisterPage'
import ResetPasswordPage from './ResetPasswordPage'
import VerifyEmailPage from './VerifyEmailPage'
import ProfilePage from './ProfilePage'
import ChangePasswordPage from './ChangePasswordPage'

You're exposing each component by adding export default class before the class declaration but the index.js functions as an entry point that groups all of these similar components so you can organize them and export them more neatly. It's really just a preference.

alexburgos avatar Jan 11 '17 05:01 alexburgos