I forgot to include this in the video, but when you run codegen you can also generate the hooks with the query names. Some developers prefer this. I don't do this here because I prefer to wrap the hook anyway. If you would like to investigate further you can check out more here: the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-apollo#withhooks
In my case it is an ease of use thing. You don't always want to use the data as-is. I created helpers here in order to make the hooks easier to call from the component that consumes the data. If you generate the hooks you still have to pass in the same data as if you used useMutation, useQuery etc. You can see this in createNewTodo for example where I wrap createTodo so that the ID is passed in every time. Both ways are equally valid. Its more of a preference thing
I forgot to include this in the video, but when you run codegen you can also generate the hooks with the query names. Some developers prefer this. I don't do this here because I prefer to wrap the hook anyway.
If you would like to investigate further you can check out more here:
the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-apollo#withhooks
Thank you for the video!!
Happy you enjoyed it!!!
why do you create custom react hooks? this library generates its own hooks or it is not the best practise ?
In my case it is an ease of use thing. You don't always want to use the data as-is. I created helpers here in order to make the hooks easier to call from the component that consumes the data.
If you generate the hooks you still have to pass in the same data as if you used useMutation, useQuery etc.
You can see this in createNewTodo for example where I wrap createTodo so that the ID is passed in every time. Both ways are equally valid. Its more of a preference thing
Thanks for adding this detail @r_alisher. I pinned a comment about it in case others don’t want to wrap their hooks and use the codegen ones.
thank you for information@@DanRNLab