React

ยท React
1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ๋จผ์ € ๊ตฌ๊ธ€ ๊ณ„์ •์œผ๋กœ Firebase Console์— ๊ฐ€์ž…ํ•˜๊ณ , ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค. ๋ฐฐํฌ ๊ธฐ๋ก์ด๋‚˜ Firebase๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์ฝ˜์†”์—์„œ ๋Œ€์‰ฌ๋ณด๋“œ์ฒ˜๋Ÿผ ๋ณด๋ฉด์„œ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‚ด ํ”„๋กœ์ ํŠธ๊ฐ€ ์˜ค๋ฅธ์ชฝ์— ์ƒ์„ฑ๋œ ๋ชจ์Šต 2. Firebase CLI ์„ค์น˜ npm์œผ๋กœ Firebase CLI ์„ค์น˜ npm install -g firebase-tools 3. ํ”„๋กœ์ ํŠธ ์ดˆ๊ธฐํ™” ๋ฐฐํฌํ•˜๋ ค๋Š” ํ”„๋ก ํŠธ์—”๋“œ ํ”„๋กœ์ ํŠธ์˜ ๋ฃจํŠธ์—์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๊ธฐ firebase init hosting ์ดˆ๊ธฐํ™” ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋ฉด, interactive ์งˆ๋ฌธ์ด ์ญ‰ ๋‚˜์˜จ๋‹ค. Project setup? Please select an option:๊ธฐ์กด ๋กœ์ปฌ ํ”„๋กœ์ ํŠธ์—๋‹ค Firebase ํ”„๋กœ์ ํŠธ๋กœ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ์ด๋‹ˆ, Use an exist..
ยท React
ํ˜„์ƒnpm run dev๋กœ ๊ฐœ๋ฐœํ™˜๊ฒฝ ์‹คํ–‰ํ•˜๊ณ  ๋ธŒ๋ผ์šฐ์ € ์˜คํ”ˆ์‹œ ์•„๋ฌด๋Ÿฐ ํ™”๋ฉด์ด ๋‚˜์˜ค์ง€์•Š๊ณ  ๋กœ๊ทธ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ์ฐํžˆ๋Š” ํ˜„์ƒ Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/msw.js?v=3f957acc' does not provide an export named 'rest'  ์›์ธvite์˜ ์บ์‹œํŒŒ์ผ์ด ์ตœ์‹ ํ™”๊ฐ€ ๋˜์ง€ ์•Š์•„ ๋‚˜ํƒ€๋‚˜๋Š” ๋ฌธ์ œ ํ”„๋กœ์ ํŠธ package.json์—์„œ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋Š” dependency ์˜์กด์„ฑ์ด ์บ์‹œ๋˜์–ด์žˆ๋Š” ์˜์กด์„ฑ์ด๋ž‘ ๋‹ค๋ฅผ ๋•Œ ๋ฐœ์ƒ ํ•ด๊ฒฐnode_modules ๋‚ด๋ถ€์— ์žˆ๋Š” vite ์บ์‹œํŒŒ์ผ์ธ `.vite ํด๋”` ์‚ญ์ œ  ์ดํ›„ ๋‹ค์‹œ npm run dev ์žฌ์‹คํ–‰ ์ด๋ž˜๋„ ๋˜์ง€์•Š๋Š”๋‹ค๋ฉด..? `node_modules` ๋‚ด..
ยท React
๋ฌธ์ œ 2๊ฐ€์ง€ ์ธํ’‹์ด ์žˆ๋‹ค. "๋น„๋ฐ€๋ฒˆํ˜ธ"๋ฅผ ๋ผ๋ฒจ๋กœ ๊ฐ€์ง€๋Š” ์ธํ’‹ 1๊ฐœ์™€ "๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"์„ ๋ผ๋ฒจ๋กœ ๊ฐ€์ง€๋Š” ์ธํ’‹ 1๊ฐœ ํ…Œ์ŠคํŠธ๋ฅผ ๋Œ๋ฆฌ๋Š”๋ฐ ์ด์ƒํ•˜๊ฒŒ "๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ" ์ธํ’‹์— ์ž…๋ ฅ๋˜์–ด์•ผํ•˜๋Š” ๊ฐ’์ด ๊ณ„์† ์œ„์˜ "๋น„๋ฐ€๋ฒˆํ˜ธ" ์ธํ’‹์— ์ž…๋ ฅ๋˜๋Š” ํ˜„์ƒ์ด ์žˆ์—ˆ๋‹ค.๋””๋ฒ„๊น…ํ•˜๊ธฐ ๋„ˆ๋ฌด ์–ด๋ ค์› ๋˜๊ฒƒ์€, ํ…Œ์ŠคํŠธ์—์„œ ์—๋Ÿฌ๋‚˜๋Š” ๋ถ€๋ถ„์€ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ ์ธํ’‹ DOM ์š”์†Œ๋ฅผ ์ฐพ์ง€ ๋ชปํ•ด์„œ๋Š” ์•„๋‹ˆ์—ˆ๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ ์ธํ’‹์€ ์ฐพ์•„์ง€๋Š”๋ฐ, ๊ทธ๊ฒŒ ์ œ๋Œ€๋กœ๋œ ์•„๋ž˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ ์ธํ’‹์ด ์•„๋‹Œ ์œ„์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ธํ’‹์œผ๋กœ ์ฐพ์•„์ง€๋Š” ๋ฌธ์ œ์˜€๋‹ค. ๋„๋Œ€์ฒด ์™œ์ด๋Ÿด๊นŒ.. ํ•˜๋‹ค๊ฐ€ Testing Playground์—์„œ ์‹œ๋„ํ•ด๋ณด๋‹ค๊ฐ€ ๋“œ๋””์–ด ์›์ธ์„ ์ฐพ์•˜๋‹ค. ์›์ธ์ปดํฌ๋„ŒํŠธ๋น„๋ฐ€๋ฒˆํ˜ธ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ ํ…Œ์ŠคํŠธ์ฝ”๋“œscreen.getByLabelText('๋น„๋ฐ€๋ฒˆํ˜ธ') input์˜ id๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ, id๊ฐ€ ..
ยท React
๋ฌธ์ œPOST/PATCH Mutation ์š”์ฒญ์‹œ ์บ์‹ฑ์„ ๋ฌดํšจํ™”ํ•˜์—ฌ ๋ฐ์ดํ„ฐ์˜ ์ตœ์‹  ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋„๋ก ์ ์šฉํ•ด๋‘์—ˆ๋‹ค.์ด๋ฏธ์ง€ ๋“ฑ๋ก POST > ์ด๋ฏธ์ง€ ๋ชฉ๋ก GET > ์ธ๋„ค์ผ ์ด๋ฏธ์ง€ PATCH > ์ „์ฒด ์ด๋ฏธ์ง€๋ชฉ๋ก GET ์ˆœ์„œ๋กœ ํ˜ธ์ถœ๋˜์–ด ๊ฐฑ์‹ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ์˜ˆ์ƒํ–ˆ์œผ๋‚˜, PATCH Mutation ์š”์ฒญ ์ดํ›„์— GET ์ฟผ๋ฆฌ๊ฐ€ ์‹คํ–‰๋˜์ง€ ์•Š์•„์„œ, ์ธ๋„ค์ผ์ด๋ฏธ์ง€๊ฐ€ ํ™”๋ฉด์— ๋ฐ”๋กœ ๋ฐ˜์˜๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค. Expected Behavior POST > GET > PATCH > GET  Current BehaviorPOST > GET > PATCH (๋ธŒ๋ผ์šฐ์ € ๋„คํŠธ์›Œํฌ) POST > PATCH > GET (์ฝ˜์†”) ์ปดํฌ๋„ŒํŠธ ์ฝ”๋“œ//ImageContainer.tsx์„œ๋ฒ„์— ์š”์ฒญ ๋ณด๋‚ด๋Š” ์ฝ”๋“œ ์กด์žฌ ์ธ๋„ค์ผ ์„ค์ •ํ•˜๋Š” ํ•จ์ˆ˜ const ..
ยท React
์ด์Šˆauthoriztion token์ •๋ณด๋กœ api์˜ ์š”์ฒญ์„ ๋ฐ›์•„์„œ ํ™”๋ฉด์— ์œ ์ €์ •๋ณด๋ฅผ ๋„์šฐ๋Š” ๋งˆ์ด ํŽ˜์ด์ง€๊ฐ€ ์žˆ๋‹ค.ํ…Œ์ŠคํŠธ๋ฅผ ๋Œ๋ฆฌ๋Š”๋ฐ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์—์„œ ์ž๊พธ ์œ ์ €์ •๋ณด๊ฐ€ ๋นˆ๊ฐ’์œผ๋กœ ๋‚˜์˜ค๋Š” ์ด์Šˆ๊ฐ€ ์žˆ์—ˆ๋‹ค. ์ปดํฌ๋„ŒํŠธ ๊ตฌํ˜„ ์œ ์ €์ •๋ณด๋ฅผ get ํ•ด์˜ค๋ ค๋ฉด ์ €์žฅ๋œ ํ† ํฐ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์„œ๋ฒ„์— ์š”์ฒญํ•ด์„œ response๋กœ ๋ฐ›์•„์™€์•ผํ•œ๋‹ค.์ด๋•Œ, ์ธ์ฆ ํ† ํฐ์€ ๋กœ์ปฌ์Šคํ† ๋ฆฌ์ง€์—์„œ ํ† ํฐ ์ •๋ณด๋ฅผ ๋ฐ›์•„์˜ค๋Š”๋ฐ, ๋กœ์ปฌ ์Šคํ† ๋ฆฌ์ง€์—์„œ ํ† ํฐ์ •๋ณด๋ฅผ ๋ฐ›์•„์˜ฌ๋•Œ localStorage Web API๋ฅผ ์‚ฌ์šฉํ•ด์„œ localStorage.getItem("token")๋กœ ๋ฐ”๋กœ ๋ฐ›์•„์˜ค๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ณ , store๋ผ๋Š” 3rd party ํŒจํ‚ค์ง€๋ฅผ ํ†ตํ•ด ์Šคํ† ๋ฆฌ์ง€์— ์ ‘๊ทผํ•œ๋‹ค. //package.json "dependencies": { "store": "2.0.12" }, ๋”ฐ..
ยท React
์˜์กด์„ฑ ํŒจํ‚ค์ง€ "devDependencies": { "jest": "29.3.1", "react": "18.2.0", ... } ๋ฌธ์ œtest ํ™˜๊ฒฝ์—์„œ png ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ชป์ฝ์–ด์˜ค๋Š” ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒ error: `process()` or/and `processAsync()` method of code transformer found at fileTranformer.cjs "/fileTransformer.cjs" should return an object or a Promise resolving to an object.   ์›์ธjest๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ฝ”๋“œ๋ฅผ JavaScript๋กœ ์‹คํ–‰ํ•œ๋‹ค. Node๊ฐ€ ์ง€์›ํ•˜์ง€ ์•Š๋Š” syntax์ธ JSX, TypeScript ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ๊ณง๋ฐ”๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด pla..
ยท React
๋“ค์–ด๊ฐ€๊ธฐํ™˜๊ฒฝnode 20.16 ํŒจํ‚ค์ง€ ์˜์กด์„ฑreact testing library 13.4.0redux toolkit 1.9.5 msw 2.3 vite 5.2.11typescript 4.9.4jest 29.3.1 msw ํ•ธ๋“ค๋Ÿฌ๋กœ ์„œ๋ฒ„ ์‘๋‹ต ๋ชจํ‚น, RTK Query๋กœ API ํ˜ธ์ถœํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ ๋ชจ์Œzip... ํ…Œ์ŠคํŠธ๋กœ ์ฝ”๋“œ ํ’ˆ์งˆ์„ ํ–ฅ์ƒ์‹œํ‚ค๊ณ ์ž ํ–ˆ์œผ๋‚˜ jest testing framework + msw 2 ํ™˜๊ฒฝ์—์„œ ์…‹ํŒ…ํ•˜๋‹ค๊ฐ€  ์ •์‹  ๊ฑด๊ฐ•์— ์œ„ํ˜‘์„ ๋ฐ›์•˜๋‹คmsw ์—์„œ๋„ ์›ƒ๊ธด๊ฒŒ ์ด๋ ‡๊ฒŒ ์…‹ํŒ…ํ•˜๋Š”๊ฒŒ ๊ท€์ฐฎ์œผ๋ฉด ~ ๋” ๋ชจ๋˜ํ•œ ํ…Œ์ŠคํŒ… ํ”„๋ ˆ์ž„์›Œํฌ ์‚ฌ์šฉํ•˜๋ ด~ ์ด๋ผ๊ณ  ๊ถŒ์žฅ..If you find this setup cumbersome, consider migrating to a modern testing fra..
ยท React
ํ…Œ์ŠคํŠธ ๋‚ด์šฉ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ jest | React Testing Library React Router์˜ useNavigate๋กœ ์—ฐ๊ฒฐ๋˜์–ด์žˆ๋Š” ํŽ˜์ด์ง€๊ฐ€ ์žˆ๋‹ค. ํ™•์ธ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์กฐ๊ฑด์„ ์ถฉ์กฑํ–ˆ๋Š”์ง€ ๊ฒ€์‚ฌ ํ›„ ๋‹ค์Œ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๋Š” ํŽ˜์ด์ง€์ด๋‹ค. ์ด๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ํ…Œ์ŠคํŠธํ•ด์•ผ ํ–ˆ๋‹ค. ์•ฝ๊ด€๋™์˜ ํŽ˜์ด์ง€์—์„œ ์ „์ฒด ๋™์˜ ์ฒดํฌ ํ›„ ํ™•์ธ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด, ๋‹ค์Œ ํŽ˜์ด์ง€์ธ ์ด๋ฆ„ ์ž…๋ ฅํŽ˜์ด์ง€๋กœ ์ด๋™ํ•œ๋‹ค. ํ…Œ์ŠคํŠธํ•˜๋ ค๋Š” ์ฝ”๋“œ Agreement.tsxexport const Agreement = () => { const navigate = useNavigate(); const [checked, setChecked] = useState(false); const handleClick = () => { if (checked) { navigate('/..
ยท React
๊ธฐ์กด ์…‹์—…api ์š”์ฒญ์€ stage ์„œ๋ฒ„์˜ url์ธ `VITE_ACCOUNTS_BASE_URL` ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ์ง€์ •ํ•œ ์ฃผ์†Œ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด์„œ ์Šคํ…Œ์ด์ง• ์„œ๋ฒ„ ์š”์ฒญ/์‘๋‹ต์„ ์ง์ ‘ ๋ฐ›๋Š”๋‹ค. ์„œ๋ฒ„์—์„œ ์‘๋‹ต์œผ๋กœ ์ฃผ๋Š” ํŽ˜์ด์ง€ ์ฃผ์†Œ๋‚˜ redirect ํŽ˜์ด์ง€ url ์ •๋ณด๋Š” `VITE_LOCAL_HOST` ๋ผ๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ฃผ์†Œ๋กœ ๊ด€๋ฆฌํ•ด์„œ ๊ฐœ๋ฐœํ•˜๋ฉด์„œ ๋ฐ”๋กœ๋ฐ”๋กœ ์„œ๋ฒ„ ์‘๋‹ต์— ๋”ฐ๋ฅธ ํŽ˜์ด์ง€ ui ๋ฅผ ํ™•์ธํ•œ๋‹ค. package.json "scripts": { "dev": "vite", "build": "vite build -m stage", "stage": "vite -m stage", } ํ™˜๊ฒฝ๋ณ€์ˆ˜ ํŒŒ์ผ๊ฐœ๋ฐœ ๋ชจ๋“œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์Šคํ…Œ์ด์ง• ๋ชจ๋“œ ํ™˜๊ฒฝ๋ณ€์ˆ˜  vite ๊ฐœ๋ฐœ์„œ๋ฒ„ ์‹œ์ž‘`npm run dev` ๋ช…๋ ์–ด๋กœ ๋กœ์ปฌ์—์„œ vite ๊ฐœ..
ยท React
This post is what I took notes from the React Testing for Beginners By Programming with Mosh.What to testTesting ComponentsHow they renderHow they responsd to user actions No tests > Bad testsBad tests are worse than No tests.Poorly written tests can get in the way and slow us down.  Test the behaviour (What the application does), not the implementation (How it's implemented)  Integration Tests ..
hana1203
'React' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก