I am having some trouble with css modules in react I dont know how to use react modules in a dynamic way
JavaScript
x
11
11
1
import classnames from 'classnames'
2
import styles from './hover.module.css
3
///
4
///
5
const [flashElements,setFlashElements]=useState(elementList.map(element => {
6
return element.classes.flash
7
}))```
8
9
///
10
///
11
I want to be able to display the classes showing the value that corresponds to the element in state . is this even possible or should I approach the problem differently I want to be to do some thing like the code below
JavaScript
1
3
1
return (
2
<a classname={styles.HOVER ,styles.flashElements[i]}>
3
Advertisement
Answer
Instead of import styles from './hover.module.css'
try using import './hover.module.css'
in your component and you can directly use the class names from your CSS file.
Use className
instead of classname
in your <a> tag