You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wonder what the best approach would be to use an atomic state with single API endpoints and without creating an additional request for every single item. That would be a major problem in my case because there can be hundreds of items.
Another note, these items are completely editable and should not refetch the entire list (this comes from the ui/ux team).
I also need the single item in some cases.
I have two possible approaches. The first one would be to simply use a custom hook with an useRecoilCallback to fetch the data and set the atoms accordingly and another one for actual usage
The benefit of this approach in my opinion is, it feels really react like and is easy to follow even with less experience in recoil.
The downside is that I must add a useEffect in every hook I create that may use special selectors for like filtering or other purposes. Because the state may not be there.
The other one that would make use of a initial items selector that contains the api response and the usage of default selectors in the atoms that use the initial items selector
The benefit here seems to be that I can let recoil do all the work and don't need to handle the fetching within components.
Also I can create much more hooks this way without thinking about not yet fetched data. Especially helpful for create additional selectors with their own corresponding hook.
On the other hand it feels a bit overcomplicated.
Both approaches have the same result. But I wonder if there are some pitfalls or other implications I'm not aware of? Or if there is a preferred way to handle this?
Other solutions are welcome too 🙏.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I wonder what the best approach would be to use an atomic state with single API endpoints and without creating an additional request for every single item. That would be a major problem in my case because there can be hundreds of items.
Another note, these items are completely editable and should not refetch the entire list (this comes from the ui/ux team).
I also need the single item in some cases.
I have two possible approaches. The first one would be to simply use a custom hook with an
useRecoilCallback
to fetch the data and set the atoms accordingly and another one for actual usageThe benefit of this approach in my opinion is, it feels really react like and is easy to follow even with less experience in
recoil
.The downside is that I must add a
useEffect
in every hook I create that may use special selectors for like filtering or other purposes. Because the state may not be there.The other one that would make use of a initial items selector that contains the api response and the usage of default selectors in the atoms that use the initial items selector
The benefit here seems to be that I can let
recoil
do all the work and don't need to handle the fetching within components.Also I can create much more hooks this way without thinking about not yet fetched data. Especially helpful for create additional selectors with their own corresponding hook.
On the other hand it feels a bit overcomplicated.
Both approaches have the same result. But I wonder if there are some pitfalls or other implications I'm not aware of? Or if there is a preferred way to handle this?
Other solutions are welcome too 🙏.
Beta Was this translation helpful? Give feedback.
All reactions