Skip to content

Instantly share code, notes, and snippets.

@marekrozmus
Created February 18, 2024 17:20
Show Gist options
  • Save marekrozmus/a009fc744c160e2a7b0a79bc7ae1dc7f to your computer and use it in GitHub Desktop.
Save marekrozmus/a009fc744c160e2a7b0a79bc7ae1dc7f to your computer and use it in GitHub Desktop.
React component for responsive background
...
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