1인 프로젝트 개발을 하던 중 전역 상태 관리가 필요해진 시점에서 누군가 나에게 말했다 useRecoil을 쓴다면 편하게 전역관리를 할 수 있으니 시도해보지 않겠냐고
애플리케이션의 동작 방식을 설명하는 모든 데이터
David Khourshid - 상태관리는 시간이 지남에 따라 상태가 변경되는 방식이다.
상태 '관리'가 되려면 기본적으로 3가지 기능을 해야한다.

// 기존 useEffect로 업데이트 해줘야하는 점
useEffect(() => {
(async () => {
await updateState();
await updateAnotherState();
}) ();
}, []);
// 업데이트 필요없이 useState와 유사한 업데이트 방식
const tempFahrenheit = atom({
key: 'tempFahrenheit',
default: 32,
});
const tempCelsius = selector({
key: 'tempCelsius',
get: ({get}) => ((get(tempFahrenheit) - 32) * 5) / 9,
set: ({set}, newValue) => set(tempFahrenheit, (newValue * 9) / 5 + 32),
});
function TempCelsius() {
const [tempF, setTempF] = useRecoilState(tempFahrenheit);
const [tempC, setTempC] = useRecoilState(tempCelsius);
state.js
export const cookieState = atom({
key: 'cookieState',
default: []
});
Cookie.js
import React from 'react'
import { cookieState } from '../../state';
import { useRecoilState } from 'recoil';
const Cookie = () => {
const [cookies, setCookies] = useRecoilState(cookieState);
return(
<div>
{cookie.map(cookie => (
<Card
cookies={cookie}
key={cookie.id}
idx={cookie.id}
/>
))}
</div>
);
}
export default Cookie;
export const sampleState = atom({
key: "sampleState",
default: 0,
});
export const sampleSelector = selector({
key: "sampleSelector",
get: ({ get }) => get(sampleState) * 2,
set: ({ set }, newValue) => set(sampleState, newValue / 2),
});
useRecoil에 대해서 알아보니 편리한 사용성과 간단한 로직이 마음에 들었다. 간결한 코드와 컴포넌트의 로직을 건드리지 않고 상태관리를 할 수 있단 점이 마음에 들었고 아직 기초적인 것만 활용해 잘은 모르지만 이를 활용해 프로젝트를 구현해보려고 한다.