I’m using react-query
to wrap API calls, I’ve added placeholderData
to don’t get undefined
during react-query
is calling the API, but I use Query Object instead adding arguments directly in useQuery()
:
export const FetchListObj = (pageOptions) => ({
queryKey: ['FetchList', pageOptions],
queryFn: () => fetchListAPI(pageOptions),
placeholderData: {
content: [],
totalElements: null
}
});
then I use object like this:
const { data, error, isLoading } = useQuery(FetchListObj(pageOptions));
it’s really strange ! because I get undefined
before data fetching then the returns fetched data…
Is there any way to solve data = undefined
in my component? or I have wrong to add placeholderData
in my query configs?