FrontEngineer JungBam

install Recoil, About Atom 본문

About Recoil

install Recoil, About Atom

정밤톨 2022. 11. 30. 17:38

React 앱을 만들고 Recoil을 사용하기 위해서는 설치를 해야한다.ㅣ

npm install recoil

Atom은 쉽게 말하면 state 값이다. Recoil을 사용하기 위해서는 atom을 생성해줘야 하는데 atom은 아래와 같이 생성하면 된다. 이렇게 생성된 atom은 atom의 값을 읽는 컴포넌트들이 이 atom을 바라보게 한다.

=> 바라본다라는 것은 atom의 변화를 감지하면 해당 컴포넌트들은 리렌더링 한다는 것이다.

import { atom } from "recoil";

export const recoilAtom = atom({ 
   key : 'RECOIL_ATOM',
   default: 0
})

 

반응형

'About Recoil' 카테고리의 다른 글

RecoilRoot  (0) 2022.11.30
Comments