mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-10-19 17:56:23 -04:00
26 lines
695 B
TypeScript
26 lines
695 B
TypeScript
import { useEffect, useRef } from "react";
|
|
import classNames from "classnames/bind";
|
|
import type { ReactNode } from "react";
|
|
|
|
import styles from "./Wallpaper.module.css";
|
|
const cx = classNames.bind(styles);
|
|
|
|
type Props = {
|
|
image: string;
|
|
tile?: boolean;
|
|
className?: string;
|
|
children: ReactNode;
|
|
};
|
|
|
|
const Wallpaper = ({ image, tile, className, ...rest }: Props) => {
|
|
const bgRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
bgRef.current.style.backgroundImage = `url(${image})`;
|
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
return <div ref={bgRef} className={cx(styles.wallpaper, { tile: !!tile }, className)} {...rest} />;
|
|
};
|
|
|
|
export default Wallpaper;
|