I am new to Apollo. I’m trying to create loading spinner. I am using class components
and I can’t use hooks. The only way to fetch data for class components
is through client.query()
The problem is that loading state is always false.
const client = new ApolloClient({
uri: '/express',
cache: new InMemoryCache(),
defaultOptions: {
query: {
fetchPolicy: 'network-only',
notifyOnNetworkStatusChange: 'true',
},
},
})
export const fetchProducts = () => {
return client
.query({
notifyOnNetworkStatusChange: true,
fetchPolicy: 'network-only',
query: PRODUCT_QUERY,
})
.then((result) => {
console.log(result.loading + '<-- spinner')
return result
})
}
@apollo/client: “^3.5.6”
react: “^17.0.2”