{
    "componentChunkName": "component---src-templates-blog-post-js",
    "path": "/20-07-27-recoil-opinion/",
    "result": {"data":{"site":{"siteMetadata":{"title":"irrationnelle","author":"irrationnelle","siteUrl":"https://dev.rase.blog","comment":{"disqusShortName":"","utterances":"irrationnelle/devlog"},"sponsor":{"buyMeACoffeeId":""}}},"markdownRemark":{"id":"c3bbca02-28ea-53c6-9d5d-366e5bfd8dd1","excerpt":"react 에서 기본적으로 제공하는 전역 state 관리 도구이다. redux 에 비해 보일러 플레이트가 현저히 줄어들었다. 상태 관리 뿐만 아니라, 메모이제이션 지원 및 컴포넌트 의존성을 줄이기 위한 reselect 역할과 외부 부수효과를 비동기적으로 다루기 위한 redux saga 같은 redux 미들웨어 기능도 겸한다. 개념 정리 atom react hooks 의  처럼 사용 가능하지만,  state 를  가 감싼 범위 내에서 전역적으로 사용이 가능하다. selector reselect…","html":"<p>react 에서 기본적으로 제공하는 전역 state 관리 도구이다.</p>\n<p>redux 에 비해 보일러 플레이트가 현저히 줄어들었다. 상태 관리 뿐만 아니라, 메모이제이션 지원 및 컴포넌트 의존성을 줄이기 위한 reselect 역할과 외부 부수효과를 비동기적으로 다루기 위한 redux saga 같은 redux 미들웨어 기능도 겸한다.</p>\n<h2 id=\"개념-정리\" style=\"position:relative;\"><a href=\"#%EA%B0%9C%EB%85%90-%EC%A0%95%EB%A6%AC\" aria-label=\"개념 정리 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>개념 정리</h2>\n<h3 id=\"atom\" style=\"position:relative;\"><a href=\"#atom\" aria-label=\"atom permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>atom</h3>\n<p>react hooks 의 <code class=\"language-text\">useState</code> 처럼 사용 가능하지만,  state 를 <code class=\"language-text\">&lt;RecoilRoot></code> 가 감싼 범위 내에서 전역적으로 사용이 가능하다.</p>\n<h3 id=\"selector\" style=\"position:relative;\"><a href=\"#selector\" aria-label=\"selector permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>selector</h3>\n<p>reselect 의 selector 처럼 초기값으로 설정된 atom 에서 필요한 값만 선택하는 것도 가능하고,</p>\n<p>인자로 전달하는 오브젝트의 <code class=\"language-text\">get</code> 키워드에 할당하는 함수 내부에 외부 부수효과를 다루는 비동기 처리도 가능하다.</p>\n<p>알아두어야 할 점은, <code class=\"language-text\">atom</code> 기반의 selector 가 아니라 외부 부수효과로 state 를 갱신하는 selector 라면</p>\n<p>초기값이 없기 때문에 비동기 작업이 완료될 때까지 state 가 <strong>존재하지 않는</strong> 상태가 된다.</p>\n<p>이걸 그대로 사용하면 에러가 발생해서 react 의 실험적 명세인 <code class=\"language-text\">&lt;Suspense></code> 등으로 컴포넌트를 감싸주어야 한다.</p>\n<h2 id=\"사용-후기\" style=\"position:relative;\"><a href=\"#%EC%82%AC%EC%9A%A9-%ED%9B%84%EA%B8%B0\" aria-label=\"사용 후기 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>사용 후기</h2>\n<h3 id=\"장점\" style=\"position:relative;\"><a href=\"#%EC%9E%A5%EC%A0%90\" aria-label=\"장점 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>장점</h3>\n<p>일단 react hooks 에 익숙하고 react hooks 기반으로 코드를 작성했다면 migration 과정도 매우 쉽다.</p>\n<p>단 migration 작업을 그냥 그대로 진행하면 selector 가 많이 늘어나서 불필요한 코드량이 늘어날 수 있다.</p>\n<p>특별히 복잡한 것도 없고, 현재 공식 문서가 약간 부실한 편이지만 api 문서의 타입 설정을 보고 조금만 실험해보면 원하는 대로 동작할 수 있게 코드 작성이 가능하다.</p>\n<h3 id=\"테스트\" style=\"position:relative;\"><a href=\"#%ED%85%8C%EC%8A%A4%ED%8A%B8\" aria-label=\"테스트 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>테스트</h3>\n<p>테스트 작성을 최근 대세로 자리잡은 듯한 testing-library 로 작성했다면 컴포넌트 렌더링 때에 초기값 설정 및 <code class=\"language-text\">&lt;RecoilRoot></code> 으로 감싸주는 작업만 잊지 않으면 기존에 작성한 테스트를 그대로 사용 가능하다.</p>\n<p>하지만 <code class=\"language-text\">selector</code> 가  외부 부수효과를 비동기 작업으로 처리한다는 점을 고려해보면 이런 작업만 따로 테스트가 가능하도록 별도로 분리해주면 좋겠다는 생각이 든다. <code class=\"language-text\">redux-saga-test-plan</code> 같은 형태로.</p>\n<h3 id=\"아쉬운-점\" style=\"position:relative;\"><a href=\"#%EC%95%84%EC%89%AC%EC%9A%B4-%EC%A0%90\" aria-label=\"아쉬운 점 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>아쉬운 점</h3>\n<p>일단 공식문서가 정말 뭐가 없다. 그만큼 직관적이고 딱 필요한 것만 있기 때문이긴 해도.</p>\n<p>그리고 redux 의 강점은 redux 에 특화된 이런저런 개발 보조도구인데 그것들을 전부 포기해야 한다는 점이 많이 아쉽다.</p>\n<p>하지만 이 부분은 recoil 을 전폭적으로 페이스북에서 밀어준다면 시간이 해결해줄 부분이라고 생각한다.</p>\n<p>개인적으로 react hooks 가 등장한 이후로 모든 컴포넌트를 함수 컴포넌트로만 작업하는 분위기를 별로 좋아하지 않는데,</p>\n<p>recoil 이 그런 경향을 가속화할 것이라는 우려도 생긴다.</p>","frontmatter":{"title":"recoil 정리","date":"July 27, 2020"}}},"pageContext":{"slug":"/20-07-27-recoil-opinion/","previous":{"fields":{"slug":"/20-07-16-test-and-spec/"},"frontmatter":{"title":"TDD 와BDD, 그리고 명세(spec)에 대하여","category":"Devops","draft":false}},"next":{"fields":{"slug":"/20-09-19-contributon-epilogue/"},"frontmatter":{"title":"2020 오픈소스 컨트리뷰톤 Mocha 후기","category":"Dev","draft":false}}}},
    "staticQueryHashes": ["3128451518","3474900066"]}