Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Importing css classes into React Component

Importing css classes into React Component

Scheduled Pinned Locked Moved JavaScript
questionjavascriptcsswpfhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simpledeveloper
    wrote on last edited by
    #1

    Hi all, I have a

    , i have imported the css files where these classes exist into my project with a statement

    import style from '../css/styles.css'

    In my react component when I am trying to reference this div as below in my React component:

    it is throwing a compiled error for me:

    ./src/components/FooterMenu.jsx
    Line 25: 'outer' is not defined no-undef
    Line 25: 'fluid' is not defined no-undef
    Line 26: 'outer' is not defined no-undef

    Search for the keywords to learn more about each error.

    What is the option to avoid these errors? Like what is the way I can reference css classes which have - in them using import reference? i have tried the following way also, but it didn't work:

    Richard DeemingR 1 Reply Last reply
    0
    • S simpledeveloper

      Hi all, I have a

      , i have imported the css files where these classes exist into my project with a statement

      import style from '../css/styles.css'

      In my react component when I am trying to reference this div as below in my React component:

      it is throwing a compiled error for me:

      ./src/components/FooterMenu.jsx
      Line 25: 'outer' is not defined no-undef
      Line 25: 'fluid' is not defined no-undef
      Line 26: 'outer' is not defined no-undef

      Search for the keywords to learn more about each error.

      What is the option to avoid these errors? Like what is the way I can reference css classes which have - in them using import reference? i have tried the following way also, but it didn't work:

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      footer-outer is not a valid Javascript identifier. It will be interpreted as (styles.footer) - outer, where the variable outer has not been defined. I've not used React, but it looks like the CSS loader has an option to convert "kebab-case" class names to "camelCase" identifiers: GitHub - webpack-contrib/css-loader: CSS Loader[^] That should let you use:

      {style.footerOuter + ' ' + style.containerFluid}

      If that doesn't work, try using the indexer on the style object:

      {style['footer-outer'] + ' ' + style['container-fluid']}


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S W 2 Replies Last reply
      0
      • Richard DeemingR Richard Deeming

        footer-outer is not a valid Javascript identifier. It will be interpreted as (styles.footer) - outer, where the variable outer has not been defined. I've not used React, but it looks like the CSS loader has an option to convert "kebab-case" class names to "camelCase" identifiers: GitHub - webpack-contrib/css-loader: CSS Loader[^] That should let you use:

        {style.footerOuter + ' ' + style.containerFluid}

        If that doesn't work, try using the indexer on the style object:

        {style['footer-outer'] + ' ' + style['container-fluid']}


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        simpledeveloper
        wrote on last edited by
        #3

        Wonderful, it did work, thanks a lot Richard.

        1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          footer-outer is not a valid Javascript identifier. It will be interpreted as (styles.footer) - outer, where the variable outer has not been defined. I've not used React, but it looks like the CSS loader has an option to convert "kebab-case" class names to "camelCase" identifiers: GitHub - webpack-contrib/css-loader: CSS Loader[^] That should let you use:

          {style.footerOuter + ' ' + style.containerFluid}

          If that doesn't work, try using the indexer on the style object:

          {style['footer-outer'] + ' ' + style['container-fluid']}


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          W Offline
          W Offline
          Wishe1991
          wrote on last edited by
          #4

          Your variable outer hasn’t been identified.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups