Skip to content

전역 상태를 사용하는 기준이 있으신가요? #5

Answered by jungpaeng
Kimbangg asked this question in Code Smell
Discussion options

You must be logged in to vote

depth를 기준으로 전역 상태를 사용할지 여부를 결정하면 안 될 것 같습니다.
또한, 저는 대부분의 서비스에서 전역 상태를 저장하기 위한 목적으로 전역 상태 관리 라이브러리(redux, jotai, zustand 등)를 사용하지 않아도 된다고 생각해요.

저는 react에서 전역 상태 관리 라이브러리 전성 시대가 열린 것이 과거 리액트의 행적과 큰 연관이 있다고 생각이 드는데요.

redux 전성시대

과거 훅도 없고 SPA라는 개념도 낯설던 시절, 리액트라는 작은 라이브러리로만 서비스의 모든 상태를 관리하는 것은 부담으로 다가왔어요.
서버에서 내려주는 수많은 데이터들과 내가 서버로 보내야 할 값들, 그리고 폼에서 다루고 있는 값, 유저 정보와 같이 대부분의 서비스에서 참조할 것 같은 값 등..

심지어 state에만 저장해두면 그 컴포넌트를 벗어날 때 상태가 초기화돼서 다시 불러와야 해요. 그래서 그당시 많은 사용자들이 선택한 게 "저 값들을 redux의 단일 스토어에 저장하고 당장 필요할 때 필요한 부분만 작게 쪼개서 가져오자." 라고 생각해요.

당시에는 정말 다른 방법이 없었거든요. useSyncExternalStore과 같은 훅도 없고 ContextAPI도 없어서 다른 페이지와 공유하는 값을 만드는 것도 번거로웠고 항상 골칫거리였는데 다소 복잡해보이긴 하지만 redux만 깐다면 이 모든 문제를 대신 해결해준다니! 정말 마법같은…

Replies: 4 comments 14 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@ohprettyhak
Comment options

@taehee-sp
Comment options

@Johnyworld
Comment options

@saengmotmi
Comment options

@taehee-sp
Comment options

Comment options

You must be logged in to vote
6 replies
@injunchoi98
Comment options

@jungpaeng
Comment options

@injunchoi98
Comment options

@jungpaeng
Comment options

@injunchoi98
Comment options

Answer selected by Kimbangg
Comment options

You must be logged in to vote
2 replies
@RyuWoong
Comment options

@milooy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment