How to invalidate query after useCreate mutation?

I am using useCreate hook on a list page for my custom requirement. I am able to mutate the data whenever user performs an create action but now how do I refresh or invalidates the list data. So, that user gets the up to date data? I have looked on to https://refine.dev/docs/api-reference/core/hooks/data/useCreate/#properties invalidates property but still confused on how to invalidate the list data.
useCreate | refine
useCreate data hook from refine is a modified version of react-query's useMutation for create mutations
4 Replies
extended-salmon
extended-salmon2y ago
Hey @dipbazz when you pass ["list"] to the invalidates property, it should invalidate the cached list queries in react-query. (Even if you don't pass anything, list is included in the default value. Also you can check https://refine.dev/docs/api-reference/core/hooks/invalidate/useInvalidate/ useInvalidate hook to run custom invalidations. If you think the invalidation is not working properly, can you please provide more info? It will be best if you can provide a repro 🙏 For the case you think it's not working properly, let me ask some questions beforehand, Do you use multiple data providers? How many resource do you have and are you using the useCreate and invalidates property inside a custom route or a refine created route? Can you share the @pankod/refine-core version installed?
environmental-rose
environmental-rose2y ago
Hey @aliemirs By looking at the useInvalidate hook I figured out that my useCreate hook and list have a different resource. So how can I invalidate list of different resource? Should I use useInvalidate? Hey @aliemirs, Thanks for your response. I have figured out the solution and it is now working.
extended-salmon
extended-salmon2y ago
@dipbazz Just saw your messages, sorry for the late response. Glad to hear you made it work. 🙏 Have a nice day! 👋
environmental-rose
environmental-rose2y ago
@aliemirs it's okay. Thanks for your help.