Replies: 1 comment 1 reply
-
You can combine custom hooks in whatever way you prefer, and it depends on your use-case. One disadvantage I can see of this approach that often times, updating and fetching are separated in components (like, a list component does the fetching while a detail component will then do the mutation). since I prefer calling hooks where I need them, if I were to call the hook to trigger a mutation, I would implicitly also get a query observer (+ refetches) that I might not need in this case. Apart from that, please be aware that with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I'm dealing with CRUD operations, I usually like to combine them into one convenient
useSave
hook which handles theGetQuery
,CreateMutation
,UpdateMutation
andDeleteMutation
. TheuseSave
hook has an optionalid
parameter to get an existing item and uses this id to distinguish between create or update in case of a change:I'm aware that creating 4 hooks (get, create, update, delete) could be an overhead in certain situations. But for Components like
CreateUser
orEditUser
I would need 3 out of 4 hooks anyway. By combining all 4 hooks into one, I can avoid the separation ofCreate
andEdit
, which share the same UI anyway. Thus, I have only oneSaveUser
component with the correspondinguseSave
hook.Is this overhead negligible or will I run in performance issues sometime? Are there any options to improve it?
Beta Was this translation helpful? Give feedback.
All reactions