如果您刚接触React,可能很难在许多简单的示例中找到快速答案。 Gatsby和React会在运行时生成类名,因此我的scss文件中的类.page1
最终会变成sections-module--page1--2SNjF
。
要选择一个元素并向其添加其他类的正确方法是什么?
import React from 'react';
import styles from '../scss/sections.module.scss';
import $ from 'jquery';
class Section extends React.Component {
componentDidMount() {
$(what??).addClass('active'); // how to select .page1 here
}
render() {
return (
<>
<section className={styles.page1}>
<h2>section 1</h2>
</section>
<section className={styles.page2}>
<h2>section 2</h2>
</section>
</>
)
}
}
export default () => (
<Section/>
)