How to target classes with queryselector when using react-css-modules

Jeanmichel Cote picture Jeanmichel Cote · Sep 10, 2016 · Viewed 16k times · Source

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?

Answer

John Xiao picture John Xiao · Sep 10, 2016

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>
}