While the previous responses are satisfactory, if you require dynamic rendering, those solutions may not be sufficient as they do not capture window values when they change.
My suggestion is to utilize modules in order to replicate the functionality of media queries, like so: [name].module.css
Here is an example code snippet:
import {useState, useEffect} from "react"
import homeStyles from "../public/Home.module.css"
export default function App() {
const [value, setValue] = useState(window.innerWidth)
useEffect(() => {
window.addEventListener("resize", () => {
setValue(window.innerWidth)
})
}, [])
return (
<div>
<h1 className={
value < 650 ? homeStyles.colorOne : homeStyles.colorTwo
}>
The value is
{
value
}
</h1>
</div>
);
}
The corresponding CSS would look like this:
.colorOne {
color: blue;
}
.colorTwo {
color: red;
}
This approach essentially emulates a media query using the provided code and the window.innerWidth value. While it may not be identical to traditional media queries, it can serve as a viable alternative for your needs.