0

I have an element with

className={this.props.shapeType}

Now this shapeType changes to Square and Diamond, so the result is class="square" or class="diamond"

The thing is that I´m using CSSComponents so to get a class from my .css I have to do:

className={s.NameOfTheClass}

where s comes from import s from ./someStyle.css

So square and diamond are not being applied and I can´t make:

className={s.this.props.shapeType}

Any suggestion?

4
  • 2
    import * as s from './someStyle.css' and try: s[this.props.shapeType] Commented Oct 12, 2016 at 11:45
  • You have written className={s[this.props.shapeType]} ? Commented Oct 12, 2016 at 11:59
  • Ah, sorry I missed something, Right, It works! Commented Oct 12, 2016 at 12:05
  • Great!. Please mark it correct and resolved. Commented Oct 12, 2016 at 12:07

1 Answer 1

1

Import all classes in s

import * as s from './someStyle.css';

and then use s object with className as key to get class:

s[this.props.shapeType]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.