React useEffect problem

~
useEffect(() => {
const fetchPins = async () => {
setLoading(true);
setError(null);

try {
let query;

if (text === "created") {
console.log("Running userCreatedPinsQuery");
query = userCreatedPinsQuery(userId);
} else {
console.log("Running userSavedPinsQuery");
query = userSavedPinsQuery(userId);
}

console.log("Generated query:", query);

const data = await client.fetch(query);

console.log("Fetched data:", data);

setPins(data);
} catch (err) {
console.error("Error fetching pins:", err);
setError(err);
} finally {
setLoading(false);
}
};

fetchPins();
console.log(
Fetching pins for text: ${text} and userId: ${userId}
);
}, [text, userId]);
~

i am working with sanity and i want to change the pins displayed when the text changes. problem is the text does change from created to save and runs the code as expected but when i change it back to created, it still runs the code with savedQuery not the createdQuery
Was this page helpful?