CJH
CJH

Reputation: 1594

React Recoil - use just the setter on the atom

React Recoil is able to give you access to your atoms as such:

  const [inEditMode, setInEditMode] = useRecoilState(seasonInEditMode);
  const seasonsDB = useRecoilValue(seasonsRC);

Where the first option works pretty much identical to React state (getter and setter), and the second gives you just the value of the chosen atom (getter).

In my code I use the above but have no use for the getter inEditMode - I only use the setter setInEditMode.

Is there a method for just declaring the atoms setter without also bringing in the getter? Something like this I guess:

const setInEditMode = useRecoilSetter(seasonInEditMode);

Upvotes: 0

Views: 759

Answers (1)

CJH
CJH

Reputation: 1594

I think it may be this but would love to get that confirmed:

const setInEditMode = useSetRecoilState(seasonInEditMode);

Upvotes: 1

Related Questions