๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ALL

(119)
๋ฆฌ๋•์Šค(Redux)์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์ž ๋ฆฌ๋•์Šค(Redux) ์ปดํฌ๋„ŒํŠธ๋“ค์˜ ์ƒํƒœ ๊ด€๋ จ ๋กœ์ง๋“ค์„ ๋‹ค๋ฅธ ํŒŒ์ผ๋“ค๋กœ ๋ถ„๋ฆฌ์‹œ์ผœ ๋”์šฑ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌ ๊ธ€๋กœ๋ฒŒ ์ƒํƒœ ๊ด€๋ฆฌ => Context API, useReducer์™€ ์œ ์‚ฌ ๋ฆฌ๋•์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๊ณผ Context API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์˜ ์ฐจ์ด ๋ฆฌ๋•์Šค๋Š”,,, ๋ฏธ๋“ค์›จ์–ด ์œ ์šฉํ•œ ํ•จ์ˆ˜(connect)์™€ Hooks(useSelector, useDispatch, useStore) ํ•˜๋‚˜์˜ ์ปค๋‹ค๋ž€ ์ƒํƒœ (๋ชจ๋“  ๊ธ€๋กœ๋ฒŒ ์ƒํƒœ๋ฅผ ํ•˜๋‚˜์˜ ์ปค๋‹ค๋ž€ ์ƒํƒœ ๊ฐ์ฒด์— ๋„ฃ์–ด ์‚ฌ์šฉ) concat: ๋ฆฌ๋•์Šค์˜ ์ƒํƒœ ๋˜๋Š” ์•ก์…˜ ์ƒ์„ฑ ํ•จ์ˆ˜๋ฅผ ์ปดํฌ๋„ŒํŠธ์˜ props๋กœ ๋ฐ›์•„์˜ฌ ์ˆ˜ ์žˆ๋‹ค. useSelector, useDispatch, useStore: ์†์‰ฝ๊ฒŒ ์ƒํƒœ๋ฅผ ์กฐํšŒํ•˜๊ฑฐ๋‚˜ ์•ก์…˜์„ ๋””์ŠคํŒจ์น˜ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ฆฌ๋•์Šค๋Š” ์–ธ์ œ ์จ์•ผ ํ• ๊นŒ? ํ”„๋กœ์ ํŠธ์˜ ๊ทœ๋ชจ๊ฐ€ ํฐ๊ฐ€? Y..
React ๊ณต๋ถ€ํ•˜๊ธฐ(5) - ๋ฆฌ์•กํŠธ ๋ผ์šฐํ„ฐ react-router๋ฅผ ํ†ตํ•œ ๋ฆฌ์•กํŠธ ์‹ฑ๊ธ€ ํŽ˜์ด์ง€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋งŒ๋“ค๊ธฐ 1. ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ๋ฒ• $ yarn add react-router-dom ํ”„๋กœ์ ํŠธ์— ๋ผ์šฐํ„ฐ ์ ์šฉ import React from 'react'; import ReactDOM from 'react-dom'; import { BrowserRouter } from 'react-router-dom'; // * BrowserRouter ๋ถˆ๋Ÿฌ์˜ค๊ธฐ import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; // * App ์„ BrowserRouter ๋กœ ๊ฐ์‹ธ๊ธฐ ReactDOM.render( , document.getElementById(..
React ๊ณต๋ถ€ํ•˜๊ธฐ(4) - API ์—ฐ๋™ํ•˜๊ธฐ 1. API ์—ฐ๋™์˜ ๊ธฐ๋ณธ $ yarn add axios GET: ๋ฐ์ดํ„ฐ ์กฐํšŒ POST: ๋ฐ์ดํ„ฐ ๋“ฑ๋ก PUT: ๋ฐ์ดํ„ฐ ์ˆ˜์ • DELETE: ๋ฐ์ดํ„ฐ ์ œ๊ฑฐ import axios from 'axios'; axios.get('/users/1'); axios.get('https://jsonplaceholder.typicode.com/users'); axios.post('/users', { username: 'blabla', name: 'blabla' }); useState์™€ useEffect๋กœ ๋ฐ์ดํ„ฐ ๋กœ๋”ฉํ•˜๊ธฐ useState: ์š”์ฒญ ์ƒํƒœ ๊ด€๋ฆฌ ์š”์ฒญ์˜ ๊ฒฐ๊ณผ ๋กœ๋”ฉ ์ƒํƒœ ์—๋Ÿฌ useEffect: ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง๋˜๋Š” ์‹œ์ ์— ์š”์ฒญ์„ ์‹œ์ž‘ import React, { useState, useEffect } from 'rea..
React ๊ณต๋ถ€ํ•˜๊ธฐ(2) - styled-components ๐ŸŽ‰ ๋ฒจ๋กœํผํŠธ์™€ ํ•จ๊ป˜ํ•˜๋Š” ๋ชจ๋˜ ๋ฆฌ์•กํŠธ CSS in JS $ yarn add styled-components import styled from 'styled-components' [polished์˜ ์Šคํƒ€์ผ ๊ด€๋ จ ์œ ํ‹ธ ํ•จ์ˆ˜ ์‚ฌ์šฉํ•˜๊ธฐ] lighten() darken() $ yarn add polished import { darken, lighten } from 'polished'; import React from 'react'; import styled from 'styled-components'; import { darken, lighten } from 'polished'; const StyledButton = styled.button` /* ๊ณตํ†ต ์Šคํƒ€์ผ */ display: inline-flex; outli..
React ๊ณต๋ถ€ํ•˜๊ธฐ(2) - CSS Module ๐ŸŽถ ๋ฒจ๋กœํผํŠธ์™€ ํ•จ๊ป˜ํ•˜๋Š” ๋ชจ๋˜ ๋ฆฌ์•กํŠธ ํ™•์žฅ์ž : .module.css ํด๋ž˜์Šค ์ด๋ฆ„์— ๋Œ€ํ•˜์—ฌ ๊ณ ์œ ํ•œ ์ด๋ฆ„๋“ค์ด ๋งŒ๋“ค์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์—, ์‹ค์ˆ˜๋กœ CSS ํด๋ž˜์Šค ์ด๋ฆ„์ด ๋‹ค๋ฅธ ๊ด€๊ณ„ ์—†๋Š” ๊ณณ์—์„œ ์‚ฌ์šฉํ•œ CSS ํด๋ž˜์Šค ์ด๋ฆ„๊ณผ ์ค‘๋ณต๋˜๋Š” ์ผ์— ๋Œ€ํ•˜์—ฌ ๊ฑฑ์ •ํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค. * classnames ์‚ฌ์šฉ ์•ˆ ํ•  ์‹œ import React from 'react'; import { MdCheckBox, MdCheckBoxOutlineBlank } from 'react-icons/md'; import styles from './CheckBox.module.css'; function CheckBox({ children, checked, ...rest }) { return ( {checked ? ( ) : ( )} {children} ); ..
React ๊ณต๋ถ€ํ•˜๊ธฐ(2) - Sass ๐Ÿ’– ๋ฒจ๋กœํผํŠธ์™€ ํ•จ๊ป˜ํ•˜๋Š” ๋ชจ๋˜ ๋ฆฌ์•กํŠธ Syntactically Awesome Style Sheets ! ํ™•์žฅ์ž : .scss / .sass $ yarn add sass sass $font-stack: Helvetica, sans-serif $primary-color: #333 body font: 100% $font-stack color: $primary-color scss $font-stack: Helvetica, sans-serif; $primary-color: #333; body { font: 100% $font-stack; color: $primary-color; } [classnames] $ yarn add classnames import classNames from 'classnames'; imp..
React ๊ณต๋ถ€ํ•˜๊ธฐ(1) - Hooks ์ข…๋ฅ˜ํŽธ ๐ŸŒน ๋ฒจ๋กœํผํŠธ์™€ ํ•จ๊ป˜ํ•˜๋Š” ๋ชจ๋˜ ๋ฆฌ์•กํŠธ ~ for ์„ฑ๋Šฅ ์ตœ์ ํ™” ~ useMemo : ์—ฐ์‚ฐํ•œ ๊ฐ’ ์žฌ์‚ฌ์šฉ useCallback : ํ•จ์ˆ˜ ์žฌ์‚ฌ์šฉ React.memo : ์ปดํฌ๋„ŒํŠธ ๋ฆฌ๋ Œ๋”๋ง ๋ฐฉ์ง€ 7. useState๋ฅผ ํ†ตํ•ด ์ปดํฌ๋„ŒํŠธ์—์„œ ๋ฐ”๋€Œ๋Š” ๊ฐ’ ๊ด€๋ฆฌํ•˜๊ธฐ import React, { useState } from 'react'; const [number, setNumber] = useState(0); ์ƒํƒœ์˜ ๊ธฐ๋ณธ๊ฐ’์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„ฃ์–ด์„œ ํ˜ธ์ถœ ํ˜ธ์ถœํ•˜๋ฉด ๋ฐฐ์—ด์ด ๋ฐ˜ํ™˜, ์ฒซ๋ฒˆ์งธ ์›์†Œ๋Š” ํ˜„์žฌ ์ƒํƒœ, ๋‘๋ฒˆ์งธ ์›์†Œ๋Š” Setter ํ•จ์ˆ˜ 11. useRef๋กœ ํŠน์ • DOM ์„ ํƒํ•˜๊ธฐ import React, { useRef } from 'react'; const nameInput = useRef(); ... nameInput.current..
React ๊ณต๋ถ€ํ•˜๊ธฐ(1) - ์ƒํƒœ๊ด€๋ฆฌ ไธญ ๋ฐฐ์—ดํŽธ ๐Ÿ”ฅ ๋ฒจ๋กœํผํŠธ์™€ ํ•จ๊ป˜ํ•˜๋Š” ๋ชจ๋˜ ๋ฆฌ์•กํŠธ ๋ถˆ๋ณ€์„ฑ !!!! push, splice XXX concat, filter, map OOO 11. ๋ฐฐ์—ด ๋ Œ๋”๋งํ•˜๊ธฐ map() : ๋ฐฐ์—ด์•ˆ์— ์žˆ๋Š” ๊ฐ ์›์†Œ๋ฅผ ๋ณ€ํ™˜ํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด ์คŒ ๊ฐ ์›์†Œ๋“ค๋งˆ๋‹ค ๊ณ ์œ ํ•œ key ๊ฐ’์„ ์„ค์ •ํ•ด์ค˜์•ผ ๋จ => ๊ทธ๋ž˜์•ผ์ง€, ์ˆ˜์ •๋˜์ง€ ์•Š๋Š” ๊ธฐ์กด๊ฐ’์€ ๊ทธ๋Œ€๋กœ ๋‘๊ณ  ์›ํ•˜๋Š” ๊ณณ์— ๋‚ด์šฉ์„ ์‚ฝ์ž…ํ•˜๊ณ  ์‚ญ์ œํ•จ import React from 'react'; function User({ user }) { return ( {user.username} ({user.email}) ); } function UserList() { const users = [ { id: 1, username: 'velopert', email: 'public.velopert@gmail.c..