안녕하세요~ 😄
React 에서는 ref를 활용하여 직접적으로 접근하시는것 보다 state를 활용하여 접근하시면 더 좋을 것 같아요~
예를 들어
const [top, setTop] = useState(0);
const [left, setLeft] = useState(0);
useEffect(() => {
setTop(Math.floor(Math.random() * 99 + 1));
setLeft(Math.floor(Math.random() * 99 + 1));
}, []);
return (
<div className="relative h-full w-full">
<p style={{ position: "absolute", top: top, left: left }}>별~</p>
</div>
);
이런식으로 접근하시면 더 좋을것 같습니다!!
useState랑 useEffect를 꼭 보시는걸 추천드리겠습니다!!
화이팅~💪