관리 메뉴

Silver Library (Archived)

Redux vs context API, 언제 쓸까? 본문

F5. Library of Tools/Redux Toolkit

Redux vs context API, 언제 쓸까?

Chesed Kim 2023. 1. 5. 23:00
반응형

개요.

이 둘의 공통점은 무엇일까요?

- store 및 애플리케이션의 state 를, 중앙화 된 위치(로서) 접근하는 기능을 제공. 

- data 를 특정/대상 component tree 에 passing 하는 것. 

- 기존 방식에 비하면 상대적으로 한눈에 상황을 보고 이해 할 수 있는 human friendly(?) 감이 있는 코드.

 

정도로 요약해봤습니다.

그리고 Redux 는 좀 더 복잡한 구조 시스템에서 용이하다는 점. 반대로 말하면, 단순히 fetch 하고 level 15 쯤에다가 하나 데이터를 dispatch 한다던지. 이런 걸 하는게 목적이라면 context API 가 나은 선택이 될 수 있을지도 모릅니다.

 

그리고 필자가 고민했던 React Query 와의 조합 같은 대체제가 있는 점도 Redux 가 필수는 아니다 라는 점. 이는 REST API 위주로 전개되는 fetching 관련 프로젝트의 경우, 더욱 Redux 보다는 이러한 다른 대체제가 눈에 걸립니다. 

 

그렇다면, Redux 는 무엇이 더 특화된 느낌일까요?

- Caching state from a server

- UI state

- other complex data management on the client

 

결론.

최선이 아닐 순 있지만, Redux 로 다양한 것을 할 수 있습니다.

 

 

When (and when not) to reach for Redux

I am a huge proponent of a couple of specific ideas. One is that you should always try to understand what problems a specific tool is trying to solve… And another is that you need to understand exactly what problems you are trying to solve in your own ap

changelog.com