I am currently developing a Next.js app (version 12.1.0) and facing an issue in my Nav component. I am attempting to select a DOM element using
const nav = document.querySelector('.nav');
However, this is triggering an error message:
TypeError: Cannot read properties of null (reading 'classList')
This problem arises because the element is being rendered as
<div class="Nav_nav___cOea"></div>
instead of having the '.nav' class that matches my CSS styles.
My CSS is written using css modules and sass within the Nav.module.sass file (which loads without any issues), but once rendered, it uses a different class name than expected. How can I target the rendered element correctly? Or is there a way to prevent next.js from generating random class names?