Is My Approach to Using Pinia-Colada with a Pinia Store for Filters Correct? #156
-
Hi everyone, I’m building a Vue 3 app using Pinia and Pinia-Colada, and I’d like to confirm if the approach I’m using to integrate my filters logic and API queries is appropriate. ContextI have a classic Pinia store called Current ApproachHere’s how I’ve set up my query using import { defineQuery } from '@pinia/colada';
import { useFiltersStore } from '@/stores/filters';
import { apiClient } from '@/api';
const filtersStore = useFiltersStore();
export const nbPosts = defineQuery({
key: () => ['nb_posts', filtersStore.apiPayload],
query: () => apiClient.post('/v1/nb_post', filtersStore.apiPayload),
}); For context, API ClientHere’s the basic API client I’m using: export const apiClient = {
async post(endpoint, payload) {
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`API error: ${response.statusText}`);
}
return response.json();
},
}; Questions
I want to ensure that this approach will be maintainable and perform well, especially since the Thanks in advance for your feedback! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I would just adapt the store usage: import { defineQuery } from '@pinia/colada';
import { useFiltersStore } from '@/stores/filters';
import { apiClient } from '@/api';
export const useNbPosts = defineQuery(() => {
const filtersStore = useFiltersStore();
return useQuery({
key: () => ['nb_posts', filtersStore.apiPayload],
query: () => apiClient.post('/v1/nb_post', filtersStore.apiPayload),
})
}); |
Beta Was this translation helpful? Give feedback.
I would just adapt the store usage: