Created
February 18, 2024 17:20
-
-
Save marekrozmus/a009fc744c160e2a7b0a79bc7ae1dc7f to your computer and use it in GitHub Desktop.
React component for responsive background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
React.useEffect(() => { | |
if (parentRef && parentRef.current) { | |
parentRef.current.style.setProperty("--bg-mobile", mobileFileUrl); | |
parentRef.current.style.setProperty("--bg-tablet", tabletFileUrl); | |
parentRef.current.style.setProperty("--bg-desktop", desktopFileUrl); | |
parentRef.current.classList.add("bg-background-set"); | |
} | |
}, [ | |
desktopFileUrl, | |
mobileFileUrl, | |
parentRef, | |
tabletFileUrl, | |
]); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment