
무라카미 하루키 - 달리기를 말할 때 내가 하고 싶은 이야기
<div id = "content" > 내용 </div>
<script>
const content = document.getElementById()("content");
const content1 = document.querySelector("content1");
</script>
useRef호출하여 ref선언const elemnetRef = useRef(); //import {useRef} from 'react'; 필요
const clickFunc() = {
elementRef.current.focus()//ref.current로 접근
}
<element ref = {elemnetRef} onClick=></element>

//버튼을 누르면 focus되는 효과
import {useRef} from 'react';
export default function UseRef() {
const input = useRef(); //useRef를 이용해
return (
<div>
<h1>UseRef</h1>
<input type="text" ref={input} placeholder="useRef연습" />
<button
onClick={() => {
input.current.focus();
}}
>
FOCUS
</button>
</div>
);
}

import React, { useRef } from 'react';
export default function UseRef() {
const num = useRef(0);
return (
<div>
<h1>UseRef</h1>
<span>ref : {num.current} </span>
<br />
<button
onClick={() => {
num.current += 1;
console.log('현재 ref값 : ', num.current);
}}
>
+
</button>
</div>
);
}

const num = useRef(0);
const [numState, setnumState] = useState(0);
return (
<div>
<h1>UseRef</h1>
<span>state : {numState} </span>
<br />
<span>ref : {num.current} </span>
<br />
<button
onClick={() => {
num.current += 1;
console.log('현재 ref값 : ', num.current);
setnumState(numState + 1);
}}
>
+
</button>
</div>
);