I just started using RTK query, but facing a problem
My app has all the setting in one big JSON, so I create an RTK query to fetch the setting. In the tutorial, the examples are about using the useQuery
hook in the component and immediately display the result, but because the setting is so big that it has multiple pages/components to display it and allow the user to change the setting
Because the setting needs to be changed, so I think it's a good idea to put the state in the store, my question is how can I put the API result into the store?
I can see a couple of methods around it
Use
useQuery
in a component and when it has resulted, then do a dispatch to put the data onto the storeput
useQuery
from API in all components use it and use it to get cached data, then there is no need to put it on the store and use the component state for setting changes (I'm not sure about this approach as there are a lots of settings - even divided across different pages, it doesn't seems right use component state to manage it)
I'm new to RTK and RTK query, just wondering what's the best/good approach?
useQuery
wherever needed and useuseState
hook to provide edit? – Ideo