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 createdQuery12 Replies
send in codeblocks
You mean i should send it in this form. Or just pictures or how?
there's instructions on how to use codeblocks in #how-to-ask-good-questions
please don't send screenshots though
Is this better?
you can get syntax highlighting if you use ```js intead of just ```, but yes!
no idea how to answer your question though, sorry
ok No problem. Atleast i learnt how to use code blocks😊
Can you send the rest of the code for the component? Also just try adding
Before the if statement. (Or you can use the web debugger if you know how to)
~~~
This is what the entire component looks like
I found the problem. LOL silly me used an uppercase in the wrong place. 🤣🤣🤣🤣🤣🤣🤣🤣🤣