Code outside the export default React component executed

Code outside the export default component in Component.js executed when I imported the component in App.js. I’m new to programming. Is it related to the feature of import (ES6)?

App.js

import Component from './Component.js'

export default function App (){
    return (
       <div>
          <Component/>
       </div>
    )
}

Component.js

console.log('test message') // printed to console, even though I didn't export it.

export default function Component (){
    return (
      <div> test </div>
    )
}

28 thoughts on “Code outside the export default React component executed”

Leave a Comment