/
d.vader
/
e2e
Обзор
Документация
Войти
/
d.vader
/
e2e
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/components/RefComponent.tsx
62 строки
1 KB
Boris Meshcheryakov
initial commit
01 окт 2025, 09:22
01 окт 2025, 09:22
3edac10
Код
Авторство
О чём код?
import { useEffect, useRef, useState } from "react"; export const RefComponent = () => { const [state, setState] = useState(1); const inputRef = useRef(null); const counterRef = useRef(0); let res = 0; const handleClick = () => { // inpu // setState(state + 1); // @ts-ignore inputRef.current?.focus(); }; const handleCounter = () => { // inpu setState(state + 1); }; useEffect(() => { // const inputEl = document.getElementById("input-id"); // console.log({ inputEl }); }, []); // console.log({ inputRef }); res = res + 1; counterRef.current = counterRef.current + 1; console.log({ res, state, counterRef }); return ( <div> <h3>RefComponent</h3> <div> <input ref={inputRef} id="input-id" type="text" placeholder="Напиши что-то" className="border px-2 rounded py-1" /> <button className="ml-2 px-3 bg-blue-500 text-white rounded" onClick={handleClick} > Focus </button> <button className="ml-2 px-3 bg-amber-950 text-white rounded" onClick={handleCounter} > click + </button> </div> </div> ); };