0%

27. Redux

Redux

State Manager

  • Without
    each component has its own storage => spaghetti code
  • With
    has one store without having each storage
  • predictable state container for JavaScript applications
    • unpredictable; random bugs, hard to fix
  • application-wide state
  • reduce function

react component = view

Reducer

  • can have multiple reducers
  • receives a state and do an action
  • reduce function
  • specify how the applicationโ€™s state changes in response
  • pure function
  • never do something like : mutate arguments, callign an API, call non-pure function

identity reducer

  • getState()
  • dispatch(action)
  • subscribe(listener)

๐Ÿ‘‡but normally uses hooks๐Ÿ‘‡

Hooks

โ€ป for React
react-query.tanstack.com/reference/useQuery
useQuery
Subscribe to our newsletter The latest TanStack news, articles, and resources, sent to your inbox.
react-query.tanstack.com
useReducer
ko.reactjs.org/docs/hooks-reference.html
Hooks API Reference โ€“ React
A JavaScript library for building user interfaces
ko.reactjs.org

Making To-Do List

๐Ÿš€ redux devTools

Do one thing -> make sure it is working -> move on to next one๏ปฟ

overview Tree

big loop

  • dispatch: sends the action to the reducer => actions in loop

index.js

๐Ÿ‘‡simplified

  • < TodoItem todo = {todo} onChange={onChangeTodo} >

โ€ป Single component as a single responsibility

  • Presentational Component
    blog.naver.com/backsajang420/221368885149
    [React] Presentational and Container Components
    [React] ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ์ปดํฌ๋„ŒํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ ์ปดํฌ๋„ŒํŠธ (Presentational and Container Components)# ์‹œโ€ฆ
    blog.naver.com

ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ์ปดํฌ๋„ŒํŠธ (Presentational Component)
ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ์ปดํฌ๋„ŒํŠธ(Presentational Component) ๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์„ฑ์งˆ์„ ๊ฐ–๋Š”๋‹ค.
โ— ์–ด๋–ป๊ฒŒ ๋ณด์—ฌ์ง€๋Š” ์ง€๋ฅผ ์ฑ…์ž„์ง„๋‹ค.
์ปจํ…Œ์ด๋„ˆ ์ปดํฌ๋„ŒํŠธ (Container Component)
์ปจํ…Œ์ด๋„ˆ ์ปดํฌ๋„ŒํŠธ(Container Component) ๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์„ฑ์งˆ์„ ๊ฐ–๋Š”๋‹ค.
โ— ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•ด์•ผ ํ• ์ง€๋ฅผ ์ฑ…์ž„์ง„๋‹ค.

React with Redux