4

React-css-modules makes up class names on the fly to limit name clashes while using standalone components. Thats awesome. But once the DOM is loaded and you need to target a class for an animation, for instance, the class names that css-modules comes up with are, in parts, randomized.

How to go about with this?

3 Answers 3

2

According from react-css-modules official doc, you can target class like bellow

render() {
    const animated = this.props.styles['animated']
    return <div className={animated}>something</div>
}
Sign up to request clarification or add additional context in comments.

Comments

1

Query selector shouldn't be necessary with react just attach a ref to the element you want and you have access to it within any function of the react component. https://facebook.github.io/react/docs/more-about-refs.html

Comments

1

So I ended up using the classNames npm module to add and remove classes to an element when I need more than one. Works like this:

let myClasses = classNames({
  'button': true,
  'special': this.state.special
})

<button className={myClasses} />

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.