WONILLISM / react-masterclass

React Master Class(feat. Nomad Coders)
0 stars 0 forks source link

5.2 ~ 3 Introduction to Recoil #28

Open WONILLISM opened 2 years ago

WONILLISM commented 2 years ago

recoil을 써서 상태관리하기

WONILLISM commented 2 years ago

Recoil을 사용하면 atoms(공유 상태)에서 selectors (순수 함수)를 거쳐 Recat 컴포넌트로 내려가는 data-flow graph를 만들 수 있다. Atoms는 컴포넌트가 구독할 수 있는 상태의 단위다. Selectors는 atoms 상태값을 동기 또는 비동기 방식을 통해 변환한다.

WONILLISM commented 2 years ago

Atoms는 상태의 단위이며, 업데이트와 구독이 가능하다. atom이 업데이트되면 각각의 구독하고있는 컴포넌트들은 새로운 값을 반영하여 다시 렌더링 된다. atoms는 런타임에서 생성될 수도 있다. Atoms는 React의 로컬 컴포넌트의 상태 대신 사용할 수 있다.

WONILLISM commented 2 years ago

Selectors는 atoms나 다른 selectors를 입력으로 받아들이는 순수 함수다. 상위의 atoms 또는 selectors가 업데이트되면 하위의 selector 함수도 다시 실행된다. 컴포넌트들은 selectors를 atoms처럼 구독할 수 있으며 selectors가 변경되면 컴포넌트들도 다시 렌더링 된다.