FE๋ฅผ ํ–ฅํ•ดโ†—โ†—

๋ฌธ์ œ ๋‚ด์šฉ ๐Ÿ™‍โ™‚๏ธํ’€์ด function solution(s) { let answer = true; const str = s.toUpperCase(); const stringArray = str.split(""); const pCount = stringArray.filter((item) => "P" === item).length; const yCount = stringArray.filter((item) => "Y" === item).length; if (pCount !== yCount) answer = false; return answer; } /* (ํ’€์ด) ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด s ๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  split์„ ์ด์šฉํ•ด ๊ฐ์ž์˜ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋‚˜๋ˆ„์–ด์ง„ ๋ฐฐ์—ด๋กœ ๋งŒ๋“ค์–ด ์ค€ ๋’ค filterํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•ด๋‹นํ•˜๋Š” ์•ŒํŒŒ๋ฒณ..
ยท React
import { useState } from "react"; const useForm = (initialState = {}) => { const [formData, setFormData] = useState(initialState); const InputChangeHandler = (e) => { const { name, value } = e.target; setFormData({ ...formData, [name]: value }); }; return { formData, InputChangeHandler, }; }; export default useForm; Custom Hook์„ ์ด์šฉํ•ด form์„ ๋งŒ๋“ค๋•Œ ์žฌํ™œ์šฉ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค์–ด๋ดค๋‹ค. ์šฐ์„  initaialState์˜ Default ๊ฐ’์„ ๋นˆ ๊ฐ์ฒด๋กœ ๋งŒ..
ยท React
๋ฉ”๋ชจ์ด์ œ์ด์…˜(memoization) ์ด๋ž€?โญ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๋ฐ˜๋ณต๋˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ ํ•ด๋†“๊ณ  ๋‹ค์Œ์— ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ ๋•Œ ๋‹ค์‹œ ๊ณ„์‚ฐํ•  ํ•„์š”์—†์ด ๋นจ๋ฆฌ ์‹คํ–‰ ํ•˜๋Š” ๊ธฐ๋ฒ•์ด๋‹ค. JavaScript์—์„œ๋Š” ํด๋กœ์ € ๋ฅผ ํ†ตํ•ด ๊ณ„์† ์œ ์ง€๋˜๋Š” ์ €์žฅ๊ณต๊ฐ„์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ๋‘ hooks ๋Š” ๋ฉ”๋ชจ์ด์ œ์ด์…˜์„ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์„ ๋ง‰์„ ์ˆ˜ ์žˆ์œผ๋‚˜, ์‚ฌ์šฉ ์ž์ฒด๋กœ๋„ ํ”„๋กœ๊ทธ๋žจ์— ์‚ฌ์šฉ๋Ÿ‰์ด ์ฑ„์›Œ์ง€๋ฏ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์ „ ์‹ ์ค‘ํžˆ ์ƒ๊ฐ ํ•ด ๋ด์•ผํ•œ๋‹ค. useMemo ์‚ฌ์šฉ๋ฒ• ๐Ÿ“„ const memo = useMemo(() => { return blabla; },[list]) useMemo๋Š” ์ฒซ๋ฒˆ์งธ ์ธ์ž๋กœ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ๋‘๋ฒˆ์งธ ์ธ์ž๋กœ ์˜์กด์„ฑ(dependency) ๋ฐฐ์—ด์„ ๋ฐ›๋Š”๋‹ค. useMemo๋Š” list๊ฐ€ ๋ณ€ํ•œ๋‹ค๋ฉด ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๊ณ  blab..
YunCow
'๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (12 Page)