selector represents a piece of derived state. You can think of derived state as the output of passing state to a pure function that derives a new value from the said state.

Derived state is a powerful concept because it lets us build dynamic data that depends on other data.

Screenshot 2024-10-19 at 7.19.34 PM.png

const even = selector({
  key: 'isEven',
  get: ({ get }) => {
    const count = get(counter);
    return count % 2;
  },
})
function IsEven() {
  const isEven = useRecoilValue(even);

  return <div>
    {isEven ? "Even" : "Odd"}
  </div>
}
  function increase() {
    setCount(c => c + 2)
  }

Screenshot 2024-10-19 at 7.26.41 PM.png