react2 [React] ref, useRef ref? JS๋ฅผ ์ฌ์ฉํ ๋์๋ ํน์ DOM์ ์ ํํด์ผํ๋ ์ํฉ์์ getElementById, querySelector ๊ฐ์ DOM Selector ํจ์๋ฅผ ์ฌ์ฉํด์ DOM์ ์ ํ ๋ฆฌ์กํธ๋ฅผ ์ฌ์ฉํ๋ ํ๋ก์ ํธ์์ DOM์ ์ง์ ์ ํํด์ผ ํ๋ ์ํฉ์ด ์๊ธฐ๋ฉด ref๋ฅผ ํ์ฉ ํจ์ํ ์ปดํฌ๋ํธ์์ **ref**๋ฅผ ์ฌ์ฉ ํ ๋์๋ **useRef** ๋ผ๋ Hook ํจ์ ์ฌ์ฉ ํด๋์ค ์ปดํฌ๋ํธ์์๋ ์ฝ๋ฐฑ ํจ์๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ **React.createRef ๋ผ๋ ํจ์ ์ฌ์ฉ** ํฌ์ปค์ค๋ฅผ ์ก์ผ๋ ค๋ฉด nameInput.current.focus() ํํ๋ก ์์ฑ const nameInput = useReft(); const onClick = () => { nameInput.current.focus(); } return( ํด๋ฆญ ) use.. 2023. 1. 24. [React] port ๋ฒํธ ๋ณ๊ฒฝํ๊ธฐ ๋ฐฉ๋ฒ1. ๋ช ๋ น์ด๋ก ์คํ (1ํ์ฑ) PORT=[์ซ์] npm run start ๋ฐฉ๋ฒ2. package.json ์์ window ... "scripts": { "start": "set PORT=3002 && react-scripts start", } ... ๋ฐฉ๋ฒ3. ํ๋ก์ ํธ๋ช /node_modules/react-scripts/scripts/start.js ์์ ํ๊ธฐ const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3002;// ์์ const HOST = process.env.HOST || '0.0.0.0'; ๋ฐฉ๋ฒ4. .env ํ์ผ ์์ฑํ๊ณ port ์ค์ ํ๊ธฐ ํ๋ก์ ํธ๋ช /.env PORT=3002 ๋ช ๋ น์ด๋ก ์คํ npm run start Reference [#. .. 2023. 1. 23. ์ด์ 1 ๋ค์