Atom boilerplate/patterns when needing a custom setter #618
Replies: 1 comment 2 replies
-
Thanks for your feedback and raising the discusson.
Yes.
We prefer atom composition style to avoid repetition. I wonder how you would like to use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there! Thanks for the library, it's been a snap to get productive with it quickly. I wanted to raise one of my confusion points that I've run into a few times, and that's with a custom updater. The various different atoms + documentation for those atoms seem to sporadically allow for a custom setter, but sometimes not.
For example, the
focusAtom
doesn't seem to allow for you to pass aSetter
function, but I'm not entirely sure why. Similarly, theatomWithImmer
doesn't allow it, but you could create a baseatomWithImmer
and then create your own derivedatom
's with custom setters.I guess my question is - is that the intended pattern of use? i.e., setup a base atom with
focusAtom/atomWithImmer/etc
, and then create another atom with the sole purpose of setting the updater function? Something likeThe same could be extrapolated for focusAtom, but the problem is that it adds an additional atom which feels a little boilerplate-y and could've been resolved by allowing to pass a custom update function in.
Beta Was this translation helpful? Give feedback.
All reactions