2

see example below:

import React, { Component } from 'react';
import styles from './Button.module.css';

class Button extends Component {
  let classNameVariable= "error-button"
  render() {
    return <button className={styles.classNameVariable}>Button</button>;
  }
}

as you saw above example, I need to use variable instead of className, to add className.

so is there a way to do it?

1 Answer 1

3

Take a look at bracket notation: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Operators/Property_Accessors

Instead of styles.clasNameVariable make it styles[classNameVariable]

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.