참고코드(redux-toolkit vs recoil): https://github.com/seungahhong/states-todos

리액트 상태 관리 로직의 한계점

Recoil은 왜 필요한 걸까??

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5f21c1d0-df1c-4445-b036-02b49b8191e3/recoil.jpeg

Recoil 철학

redux, reducer, constant

useEffect(() => {
  (async () => {
		await fetch~~
    -> redux 호출
  })();

}, []);

const allMainFetch = selector({
  key: 'allMainFetch',
  get: async ({ get }) => await get(fetch~~)
  })
});

const main = useRecoilValue(allMainFetch());
// 파생데이터
const firstAtom = atom({
  key: 'firstAtomKey',
  default: 1
});

const secondAtom = atom({
  key: 'firstAtomKey',
  default: 1
});

const cumulatedSelector = selector({
  key: 'cumulatedSelector',
  get: ({ get }) => {
    return get(firstAtom) + get(secondAtom)
  } 
});

// atom
import {atom, useRecoilState} from 'recoil';

const counter = atom({
  key: 'myCounter',
  default: 0,
});

function Counter() {
  const [count, setCount] = useRecoilState(counter);
  const incrementByOne = () => setCount(count + 1);

  return (
    <div>
      Count: {count}
      <br />
      <button onClick={incrementByOne}>Increment</button>
    </div>
  );
}