Dan Rubio Dan Rubio - 1 month ago 7
React JSX Question

Why is my const not being exported?

I have a file called

style.js
with the following content:

const CenterStyle = {
width: 800,
backgroundColor: '#FFFFFF',
marginLeft: 300,
marginTop: 100
}

export { CenterStyle };


I have a
skills.js
file with the following contents:

import React, { Component } from 'react';
import { CenterSyle } from './style';

class Skills extend React.Component
.....React code......


and then finally in my
App.js
file I import the whole
Skills
class:

import Skills from './skills'


The problem I'm getting is that in my
skills.js
, my
CenterStyle
const is
undefined
. It's not being imported. What can I be doing wrong?

Answer

Two things

Either you can try to use export before const as

export const CenterStyle = {
  width: 800,
  backgroundColor: '#FFFFFF',
  marginLeft: 300,
  marginTop: 100
}

and import it as

import { CenterSyle } from './style';

or

have a default export

const CenterStyle = {
  width: 800,
  backgroundColor: '#FFFFFF',
  marginLeft: 300,
  marginTop: 100
}

export default CenterStyle ;

and import it as

import CenterSyle from './style';