redux-toolkit
redux-toolkit copied to clipboard
RTK Query: placeholder data
Is there any way to provide placeholder data when executing a query?
For example if I have the following:
const { data } = useMyCoolQuery();
I'd like data
to contain a default value instead of just being undefined while it is still loading.
const { data = myDefaultValue } = useMyCoolQuery();
would do the trick :)
Yeah, but that means that anywhere I'd like to use my query I'd have to add a default value. I'd like for that to be possible on a slightly higher level, preferably the same place as I'm defining my request
Something similar to React Query would be great: https://react-query.tanstack.com/guides/placeholder-query-data
@phryneas , anything we want to consider doing here?
what about a way to extract the default/example values from the openapi spec and instantiate new objects from the generated types that include the defaults. this could be used as described above in the query. but it would also be useful for new records that have no data yet.