본문 바로가기

카테고리 없음

공부기록, 2021-08-04(react 기본구조)

  - recoil 사용예제
    - recoil 기본구조
```
//atom const buttonClickCountState = atom({ key: 'buttonClickCountState', default: 0, }); //selector const buttonLabelState = selector({ key: 'buttonLabelState', get: ({get}) => { const count = get(buttonClickCountState); return `${buttonClickCount}번 클릭함`; }, }); //component function button() { const [buttonClickCount, setButtonClickCount] = useRecoilState(buttonClickCountState); const buttonLabel = useRecoilValue(buttonLabelState); return ( <button onClick={() => setButtonClickCount((count) => count + 1)}> {buttonLabel} </button> ); }