- 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> ); }
카테고리 없음