onMount doesn't work for Atoms referenced in useAtomCallback #2053
-
Link to reproductionhttps://codesandbox.io/s/boring-jackson-7d648z?file=/src/App.js Check ListPlease do not ask questions in issues.
Please include a minimal reproduction.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
There doesn't seem docs clarifying the behavior, but |
Beta Was this translation helpful? Give feedback.
-
@dai-shi Thanks your reply! But this will result in the Atom used in useAtomCallback never being unmounted, and if it is a continuously running timer, it will execute indefinitely until it dies. In my real-world application, multiple table components use the same filtering option, so I defined a filtering option atom. Different tables are switched through the Tab component, and the Atom that retrieves data is obtained in useAtomCallback. This causes the request for obtaining data from Table A to continue to be sent when I switch from Table A to Table B after updating the filtering option atom. I don't know what the best practice of jotai is for dealing with this scenario. (Because I want to manually control the Loading status of the page and I must delay setting the data, I am using useAtomCallback here.) |
Beta Was this translation helpful? Give feedback.
I see.
If you want such a control, it means it's not declarative, but imperative. Whatever it means, it's something like this in Jotai best practice: