avatar

Javascript 42

  • Published on
    ### useReducer ```javascript const [state, dispatch] = useReducer(reducer, initialArg, init); ``` `useState`์˜ ๋Œ€์ฒด ํ•จ์ˆ˜๋‹ค. ๋‹ค์ˆ˜์˜ ํ•˜์œ— ๊ฐ’์„ ๋งŒ๋“œ๋Š” ๋ณต์žกํ•œ ๋กœ์ง, ํ˜น์€ ๋‹ค์Œ state๊ฐ€ ์ด์ „ state์˜ ์˜์กด์ ์ธ ๊ฒฝ์šฐ์— ์“ด๋‹ค. ๋ญ๊ฐ€ ๋ญ”์ง€ ๋ชจ๋ฅด๊ฒ ์œผ๋‹ˆ๊นŒ ์˜ˆ์ œ๋ฅผ ๋ณด์ž. ...
  • Published on
    # Hooks API Hook์€ react 16.8์—์„œ ์ถ”๊ฐ€๋œ ๊ฐœ๋…์œผ๋กœ, Hook์„ ์‹œ์šฉํ•˜๋ฉด class๋ฅผ ๊ฐ–์„ฑํ•˜์ง€ ์•Š์•„๋„ state๊ด€๋ฆฌ์™€ ๊ฐ™์€ react์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ## ๊ธฐ๋ณธ Hook ### useState ```javascript const [state, setState] = useState(initialState); setStat...
  • Published on
    ๋ฉ์ฒญ์ด๋ผ ๊ทธ๋Ÿฐ์ง€ `reduce` ํ•จ์ˆ˜๊ฐ€ ์ž˜ ์ดํ•ด ๋˜์ง€ ์•Š์•˜๋‹ค. ## Reduce ```javascript const list = [1, 2, 3, 4, 5]; const initValue = 10; const totalSum = list.reduce( (accumulator, currentValue, currentIndex, array) => { ...