개요
작고 간단한 상태값까지 리덕스를 사용하는 경우도 종종 보는데, 간단한 값들은 useState를 사용하는 내 입장에서는 상당히 불필요하다는 생각이 들었다. 찾아보니 역시 이런 생각을 하는 사람들이 이미 많이 있었고 쓸만한 대체제들도 많이 생겨나고 있는 듯 하다.
리덕스가 반드시 필요한 상황과, 리덕스를 안쓴다면 어떻게 바꿔야할지, 또 사람들의 생각들을 정리하고자 한다.
대립되는 의견
- 체계적인 관리를 위해 모든 상태값이 중앙 집중식으로 관리될 필요가 있다.
- 특별한 상황을 제외하고는
리덕스
를 쓰는 것은 과한 행위이며, 오히려 생산성만 저하시킨다.
리덕스
리덕스의 등장이 혁명이라는 점은 부정할 수 없다. immutable data를 가진 global store를 가능하게 하였고, 무엇보다 컴포넌트 간의 prop-drilling 이슈를 해결했다.
애플리케이션 전역에서 불변 데이터를 공유하기 위해서 리덕스는 여전히 매우 우수하고 확장성이 뛰어난 툴이다.
의문1
애초에 global store가 왜 필요할까?
지금 내가 개발하는 프로젝트가 그만큼 엄청나게 복잡한가에 대해 생각해볼 필요가 있다.
리덕스로 너무 많은 작업을 하려는 것은 아닐까?
의문2
리덕스는 캐시가 아니다.
I'd argue that at a low level of complexity, useuseReducer
,useState
anduseContext
. At a high level of complexity, useXState
/useContext
. XState handles complexity much better thanRedux
.
I agree with your statements about Redux. The problem honestly is the way it's used. If used to only store state that is actually global, it's fine. However, I think most of the time a lot of us like to default to throwing things into the global store to avoid prop drilling. You can simply usecontext
these days to avoidprop drilling
. We've been replacing our application at work from Redux and moving towards usinguseState
anduseReducer
, along with context. It's been fantastic. If you're interested, you can check out my pattern for React Context