I want to change the background based on the time of the day. So I get this function in js, as CSS cannot use conditional logic. But it is not working, and it seems that the url is not right.
I have tried "URL('path')", and it is not working in react. How chould I change the background image in react?
[![enter image description here][1]][1]
import { getTheme } from "../models/themes.ts"
import day from "../assets/images/gallaxyDay.png"
import night from "../assets/images/gallaxy.jpeg"
// fixme: this is not working, still cannot find why
export function getBackgroundStyles() {
if (getTheme() == "day") {
return {
"backgroundRepeat": "repeat",
"backgroundImage": "url(" + { day } + ")"
}
}
return {
"backgroundRepeat": "repeat",
"backgroundImage": `url(${night})`
}
}
class Hall extends React.Component {
render() {
let styles = getBackgroundStyles()
return <div className="hall">
<Sidebar style={{ styles }} />
<Feeds />
<Creation></Creation>
</div>
}
}
[1]: https://i.stack.imgur.com/8FPfr.png