Question about enabled: false
#7855
-
From #1196 here is a quick and dirty example: https://codesandbox.io/p/sandbox/elegant-cdn-5hhvhh const useDataQuery = (props) => {
return useSuspenseQuery({
queryFn: () => {
return { a: 1, b: 2, c: 3 };
},
queryKey: ["test"],
...props,
});
};
const ComponentOne = () => {
const { data } = useDataQuery();
return <div>ComponentOne {JSON.stringify(data)} </div>;
};
const ComponentTwo = () => {
const { data } = useDataQuery({
enabled: false,
select: (data) => {
console.log("inside Component2 select method");
return data.a + data.b;
},
});
return <div>ComponentTwo {JSON.stringify(data)} </div>;
}; The query in ComponentTwo is forever I'd expect ComponentTwo data to be undefined for ever until I change Original response from @TkDodo #7721 (comment) (because I messed up and posted it in the wrong issue)
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
The follow up question I had (in the wrong thread, and why I decided to create this discussion instead) is there any way to have the query in To me it's kind of suboptimal that the logic in |
Beta Was this translation helpful? Give feedback.
-
Same here. Just testing with
|
Beta Was this translation helpful? Give feedback.
sorry, that's just not how it works. It also seems to be an "optimization" that isn't necessary. There is nothing to optimize here. Just remove the
enabled
and you're fine 🤷Btw:
enabled
doesn't exist onuseSuspenseQuery
.