An alternative util function that can be used to reset recoil state #1299
kelvinsekx
started this conversation in
Ideas
Replies: 2 comments
-
The |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks that resolved it...passing a callback into the returned function from useResetRecoilState. I am only rewriting the example below so it could help any other person who tries reading this. // given this is react component
const resetter = useRecoilState(atomName);
<button onClick={()=>resetter(clearInterval(ID))}>Stop</button> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Most atimes to reset a state requires an additional action other than a simple reset to initial state.
For example given a Timer app. Simply calling useResetRecoilState() would not stop the already called setInterval function. To do this, there is a need to reset the timerID too. See my example below to get a better glimpse.
`
const reset = () => {
clearInterval(timeID);
useResetRecoilState(timeState)
}
<button onClick={reset}>Stop</button>
`
Trying this out would obviously not work cause useResetRecoilState is a React hook that shouldnot be called in a callback...
Can we have an alternative util function that can be called in such manner in the reset function?
Beta Was this translation helpful? Give feedback.
All reactions