0

Is there an easy way to reset state of an atomFamily?

For individual atoms there's useResetRecoilState or reset within useRecoilTransaction_UNSTABLE. Without such a hook or function, the client must iterate over a stored list of keys in order to reset each individual atom from the atomFamily.

Taylor Johnson
  • 1,845
  • 1
  • 18
  • 31

1 Answers1

1

An atomFamily just creates a helper layer for a map of atoms. So internally, Recoil would also just iterate over every given atom and reset it. There is no API that would enable this out of the box.

So, since you need to know every atom reference in your application anyway, just iterate over them and reset the state.

Johannes Klauß
  • 10,676
  • 16
  • 68
  • 122