๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

๐Ÿ“— React15

[React] sticky Header CSS๊ฐ€ ๋ณ€ํ•˜๋Š” sticky Header ๋งŒ๋“ค๊ธฐ์™€ ์ตœ์ ํ™” ์—ฌ๋Ÿฌ ์›น์‚ฌ์ดํŠธ์—์„œ๋Š” scroll๊ณผ ๊ด€๊ณ„์—†์ด ์ƒ๋‹จ์— ๋ถ™์–ด์žˆ๋Š” sticky header๋ฅผ ์ž์ฃผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ์š”, ์•„๋ž˜ ์˜ˆ์‹œ์™€ ๊ฐ™์ด ํŠน์ • ์˜์—ญ์—์„œ css๊ฐ€ ๋ฐ”๋€” ์ˆ˜ ์žˆ๋Š” header๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. โš™๏ธ ์‚ฌ์šฉ ์Šคํƒ : React, emotion/css ๐Ÿ“Œ ๊ธฐ๋ณธ ๊ตฌ์กฐ ์ƒ์„ฑํ•˜๊ธฐ ํ—ค๋”๋Š” ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉํ•  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๊ธฐ ๋•Œ๋ฌธ์— Header๋กœ ๋ถ„๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค. App.js import { css } from "@emotion/react"; import Header from "./Header.jsx"; export default function App() { return ( ); } const wrapStyle = css` `; Header.jsx import { css } from "@emotion/react"; .. 2022. 5. 17.
๊ทธ๋ฆผ์œผ๋กœ ๋ณด๋Š” Error Boundaries | Error Boundary์˜ ๋“ฑ์žฅ JS component์˜ error๋Š” React ์ƒํƒœ ํ๋ฆ„์„ ๋ฐฉํ•ดํ•˜๊ณ  ์ˆจ์€ ์—๋Ÿฌ๋ฅผ ๋ฐœ์ƒํ‚จ๋‹ค. ์ด๋Ÿฐ ์˜ค๋ฅ˜๋กœ ์ธํ•ด app ์ „์ฒด๋ฅผ ์ •์ง€์‹œ์ผœ์„  ์•ˆ๋˜๋ฏ€๋กœ "error boundary"๊ฐ€ ๋“ฑ์žฅํ–ˆ๋‹ค. โœจ Error bounaries๋Š” ์ž์‹ component tree ์–ด๋””์„œ์—๋‚˜ ์ผ์–ด๋‚œ JS error ๋ฅผ ์žก๊ณ , error๋ฅผ logingํ•˜๊ณ  fallback UI๋ฅผ ๋ณด์—ฌ์ค€๋‹ค. ๋‹ค๋งŒ ์•„๋ž˜ error๋“ค์€ catch ํ•˜์ง€ ์•Š๋Š”๋‹ค ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ๋น„๋™๊ธฐ code ( setTimeout ... ) SSR (server side rendering) error boundary ์ž์‹์ด ๋ฑ‰๋Š” error Error Boundary์˜ ์‚ฌ์šฉ์ฒ˜์™€ Uncaught Errors Error Boundaries๋Š” J.. 2022. 4. 30.
textarea ์ค„ ์ˆ˜์— ๋”ฐ๋ผ style ๋ณ€๊ฒฝํ•˜๊ธฐ ( line count์— ๋”ฐ๋ฅธ border radius์„ค์ • ๋ฐ textarea line count ๊ฐœ์ˆ˜๋ฅผ ์ด์šฉํ•œ CSS ์„ค์ • ) ๋””์ž์ธํŒ€์—์„œ ์š”์ฒญ์ด ๋“ค์–ด์™”๋‹ค. textarea์— ๋“ค์–ด๊ฐ€๋Š” line์— ๋”ฐ๋ผ border-radius๊ฐ€ ๋‹ฌ๋ผ์กŒ์œผ๋ฉด ์ข‹๊ฒ ๋‹ค๋Š” ์š”์ฒญ! ๋ฌธ์ œ๋Š” ํ•ด๋‹น ๋ถ€๋ถ„์„ ์‚ฌ์šฉํ•˜๋Š” ๊ณต๊ฐ„์˜ text area์˜ width๊ฐ€ ๊ณ ์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋Š” ์ ์ด๋‹ค. ์œ ์ €์˜ ๊ธฐ๊ธฐ๋Š” ์ •๋ง ๋‹ค์–‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— width๋ฅผ ๊ณ ์ •ํ•  ์ˆ˜ ๋Š” ์—†์—ˆ๋‹ค ex) iphone se์—์„œ 3์ค„์ผ๊ฒŒ z-fold์—์„œ๋Š” 1์ค„์ด ๋  ์ˆ˜ ์žˆ๋‹ค.. ๐Ÿ˜… 1) Textarea์˜ text value๋ฅผ ์ค„๋ฐ”๊ฟˆ ๊ธฐ์ค€์œผ๋กœ split ์ฒ˜์Œ ์ƒ๊ฐํ•œ ๋ฐฉ๋ฒ•์€ text area์˜ value๋ฅผ ์žก์•„์„œ splilting ํ•˜๋Š” ๋ฒ•! const getCurInputTextLineCnt = useCallback((text) => { const lines = text?.split(/\r|\r\n|\n/); co.. 2022. 4. 25.
[React] OAuth Github ๋กœ๊ทธ์ธ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „๋ถ€ํ„ฐ ๋„ˆ๋ฌด๋‚˜๋„ ํ•ด๋ณด๊ณ  ์‹ถ์—ˆ๋˜ ๊นƒํ—ˆ๋ธŒ OAuth ๋กœ๊ทธ์ธ์„ ์„ฑ๊ณต์ ์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค. ๊ตฌํ˜„๋‹จ๊ณ„์™€ ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ด๋ณผ ์˜ˆ์ •! ๐Ÿ“Œ ํ”„๋กœ์ ํŠธ ๊ตฌ์„ฑ * React ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ (jsx) ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•œ ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค! * BE์™€ ํ•จ๊ป˜ํ•œ ํ”„๋กœ์ ํŠธ๋กœ BE ๋‹จ์—์„œ๋Š” access-token ๋ฐœ๊ธ‰๊ณผ ์ •๋ณด ์š”์ฒญ์„ ๋งก์•„ ์ฒ˜๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค. * FE๋‹จ์—์„œ๋Š” code์š”์ฒญํ•œํ›„์— Github ๊ณ„์ • ์ •๋ณด๋ฅผ ๋ฐ”๋กœ ์š”์ฒญํ–ˆ์Šต๋‹ˆ๋‹ค. ๊นƒํ—ˆ๋ธŒ ๋กœ๊ทธ์ธ ๊ตฌํ˜„์„ ๊ฒ€์ƒ‰ํ•ด๋ณด๋ฉด ๊ตฌํ˜„ํ•˜๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์ง€๋งŒ ํฌ๊ฒŒ ๋‘๊ฐ€์ง€๋กœ ๋‚˜๋‰˜๋Š” ๋Š๋‚Œ์„ ๋ฐ›์•˜๊ณ , 2๋ฒˆ ๋ฐฉ๋ฒ•์œผ๋กœ ์ฒ˜๋ฆฌํ–ˆ๋‹ค . 1) FE๋‹จ์—์„œ code ์š”์ฒญํ•œ ํ›„ POST ๋กœ jwt ์š”์ฒญ : ์ฐธ๊ณ  (https://devhyun.com/blog/post/15) 2) โœ… FE๋‹จ์—์„œ code ์š”์ฒญํ•œ ํ›„ GET์œผ๋กœ jwt ์š”์ฒญ .. 2021. 6. 5.
[React] ReactHooks & Context API ๋ฅผ ์ด์šฉํ•œ state ๊ด€๋ฆฌ ( VS Redux) ๐Ÿ“Œ React์˜ ์ƒํƒœ๊ด€๋ฆฌ๋Š” ์–ด๋–ป๊ฒŒ ์ง„ํ–‰๋˜๊ณ  ์žˆ์—ˆ๋‚˜? React ์—์„œ ์„œ๋กœ ๋‹ค๋ฅธ component๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์€ props drilling ์ด๋‹ค . top๋ ˆ๋ฒจ์˜ components์—์„œ bottom๋ ˆ๋ฒจ์˜ components ์—๊ฒŸ ์†์„ฑ์„ ์ „๋‹ฌํ•ด์•ผ ํ•œ๋‹ค. < ์‹ค์ œ TodoList ํ”„๋กœ์ ํŠธ ๋‹น์‹œ props drilling ์ƒํ™ฉ Atomic design ํŒจํ„ด์„ ๊ณ ๋ คํ•˜์—ฌ ๋งŒ๋“  ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•  ๋‹น์‹œ * TodoList Column์„ ๋ˆ„๋ฅด๋ฉด popup์ด ๋‚˜์˜ค๊ณ  * ๊ทธ ์•ˆ (์˜์•ˆ์˜์•ˆ)์˜ Buton์„ ๋ˆ„๋ฅด๋ฉด popup์ด ๋‹ซํžˆ๋Š” ๋™์ž‘์„ ์ž‘๋™์‹œํ‚ฌ๋•Œ popup state๋ฅผ ๋Œ๊ณ ๋Œ๊ณ  ๋“ค์–ด๊ฐ€์•ผ ํ–ˆ๋‹ค... ์ด๊ฑธ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”โญ๏ธ global state๊ฐ€ ๋ชจ๋“  components์—๊ฒŒ ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ ๊นŠ์ด๊ฐ€ ๊นŠ๋“  ๊ด€๊ณ„๊ฐ€ ๋ณต์žก.. 2021. 5. 4.
[React] json-server์—์„œ axios ๋กœ ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ json serve ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•ด์„œ CRUD๋ฅผ ๊ตฌํ˜„ํ•ด ๋ณด์ž json-server ์„ค์น˜ npm install -g json-server db.json ํŒŒ์ผ ์ƒ์„ฑ { "todos": [ { "id": 1, "content": "HTML", "completed": true }, { "id": 2, "content": "CSS", "completed": false }, { "id": 3, "content": "Javascript", "completed": true } ], "users": [ { "id": 1, "name": "Lee", "role": "developer" }, { "id": 2, "name": "Kim", "role": "designer" } ] } server.js์ƒ์„ฑ // server.. 2021. 4. 12.
[React] CRA๋กœ ํ”„๋กœ์ ํŠธ ์ดˆ๊ธฐ ์„ธํŒ… create react app CRA ์„ค์น˜ //npx create-react-app {ํ”„๋กœ์ ํŠธํŒŒ์ผ๋ช…} npx create-react-app movie_app https://rrecoder.tistory.com/96?category=955706 React ๋ฆฌ์•กํŠธ๋ž€, ๋ฆฌ์•กํŠธ ์ž‘์—…ํ™˜๊ฒฝ ์„ค์ • ์‚ฌ๋žŒ๋“ค์ด ์ข‹์•„ํ•˜๊ณ , ์ธ๊ธฐ์žˆ๊ณ  , ๊ฐ„ํŽธํ•œ ํ”„๋ ˆ์ž„์›Œํฌ! ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ๋ฐ˜์ด๊ธฐ๋•Œ๋ฌธ์— ๋ฐฐ์šฐ๋Š”๋ฐ๋„ ๋ถ€๋‹ด์ด ์—†๋‹ค. ๋ฆฌ์•กํŠธ๋ฅผ ์ตํ˜€๋ณด๊ณ  ์ง์ ‘ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ์œ„ํ•ด ๋…ธ๋งˆ๋“œ์ฝ”๋”์˜ ReactJS ๋กœ ์˜ํ™” ์›น์„œ๋น„์Šค ๋งŒ rrecoder.tistory.com ์ด๋ ‡๊ฒŒ ์„ค์น˜๋ฅผ ํ•˜๋ฉด ์‚ฌ์šฉํ•˜์ง€ ์•ˆ์•„๋„ ๋  ํŒŒ์ผ๊ณผ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ๋„˜์นœ๋‹ค. ๋‚˜์˜ ์ƒˆ๋กœ์šด ํ”„๋กœ์ ํŠธ๋ฅผ ์œ„ํ•ด ์ง€์›Œ๋„ ๋  ํŒŒ์ผ๋“ค์„ ์‹ธ๊ทธ๋ฆฌ ์ง€์›Œ๋ณด์ž!! 1๏ธโƒฃ ์‚ญ์ œ 1๏ธโƒฃ- 1 ) ํŒŒ์ผ ์‚ญ์ œ ์ดˆ๊ธฐ ์ƒํ™ฉ ์ด๋ ‡๊ฒŒ ํŒŒ์ผ๋“ค.. 2021. 4. 11.
[React] React ์˜ ํŠน์ง•, JSX ์ดํ•ดํ•˜๊ธฐ CSR ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง data(json)๊ฐ€์ ธ์™€ ํด๋ผ์ด์–ธํŠธ์—์„œ ๋ Œ๋”๋ง ํ•˜์—ฌ ๊ฒฐ๊ณผ ๋ณด์—ฌ์คŒ json๋ฐ์ดํ„ฐ๋งŒ ๋ฐ›์•„์™€์„œ ํด๋ผ์ด์–ธํŠธ ๋ Œ๋”๋ง ํ•˜์—ฌ๋ผ SSR ์„œ๋ฒ„ ์‚ฌ์ด๋“œ๋ Œ๋”๋ง ๋ˆ„๋ฅด๋ฉด ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ ( ํŽ˜์ด์ง€ ์ด๋™) html ํŒŒ์ผ์„ ๊ฐ€์ ธ์™€์„œ ์„œ๋ฒ„์—์„œ ์ƒˆ๋กœ ๋ Œ๋”๋ง ๐Ÿ“Œ SPA ( Single Page Application ) ํ•œ single page์—์„œ ๋ฐ์ดํ„ฐ ๋ณ€ํ™”๊ฐ€ ๋‹ค ์ด๋ฃจ์–ด์ง€๋„๋ก ๋งŒ๋“  ํŽ˜์ด์ง€ ์ƒˆ๋กœ๊ณ ์นจ ์—†์ด ๋น ๋ฅด๊ฒŒ ๋Œ€์‘ํ•˜๋„๋ก ๋งŒ๋“ฆ ๋ฐฑ์—”๋“œ API ์ œ๊ณต -> ํด๋ผ์ด์–ธํŠธ template ์ž‘์—… -> ๋ Œ๋”๋ง ํด๋ผ์ด์–ธํŠธ์—์„œ data๋“ค์„ ํŒŒ์‹ฑํ•˜๋ฉด์„œ JS๊ฐ€ ๋ณต์žกํ•ด์กŒ๋‹ค. ๋งŽ์€ ๋ชจ๋“ˆ๋“ค์„ ์–ด๋–ป๊ฒŒ ๊ฐ์ฒด์ง€ํ–ฅํ˜•์œผ๋กœ ๋งŒ๋“ค๊นŒ? ๊ทธ ์ค‘์— ๋น„๋™๊ธฐ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ๋„ ์™„๋ฃŒํ•ด์•ผ ํ•จ SPA๋ฅผ ์œ„ํ•ด ํ•„์š”ํ•œ ๊ธฐ์ˆ  ๋ผ์šฐํŒ… ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง ์ƒํƒœ๊ด€๋ฆฌ .. 2021. 4. 11.
ReactHooks ์ •๋ณตํ•˜๊ธฐ 1ํƒ„ ( useState, useClick ) ๊ธฐ๋ณธ์ ์ธ ๊ตฌ์กฐ useHooks๋ผ๋Š” Hook์ด ์žˆ์„ ๊ฒฝ์šฐ const useHooks = (initial, ~) =>{ const [ curr, setCurr ] = useState(initial, ~); return { currItem : curr, changeItem: setCurr } } const App = () =>{ const {currItem , changeItem} = useHooks(์ดˆ๊ธฐ๊ฐ’); {currItem} {changeItem(0)} } ๐Ÿ”ฅ useState ๐Ÿ”ฅ useInput (์ดˆ๊ธฐ๊ฐ’ , ์œ ํšจ๊ฒ€์‚ฌfunction) input ์„ ๋„ฃ๊ณ , ์›ํ•˜๋Š” ์ž…๋ ฅ ์กฐ๊ฑด์— ํ•ด๋‹นํ•˜๋Š” ๊ฐ’๋งŒ ๋ฐ›๊ธฐ //useInput Hooks const useInput = (initialValue, validator) => .. 2021. 4. 6.
๋ฐ˜์‘ํ˜•