-
Hi, I'm trying to make two custom hooks: one that fetches data, and another that filters that data. I need both the filtered and unfiltered results. This is what I've tried. const useAllRecords = (parameters) => {
return useQuery(["allData", parameters], () => getData(parameters));
};
const useFilteredRecords = (parameters) => {
const { data } = useQuery(["getData", parameters], () => getData(parameters));
if (data) {
const result = filterRecords(data);
return useQuery("filteredData", async () => {
return await result;
});
}
}; The first query, useAllRecords, works fine. I get data and can destructure it where I call it in my app. The second query, useFilteredRecords, gets into the var obsRef = React.useRef();
if (!obsRef.current) {
obsRef.current = new Observer(queryClient, defaultedOptions);
} I have no idea why obsRed would be |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You are calling useQuery in an if statement, which violates the rules of hooks. Have a look at the |
Beta Was this translation helpful? Give feedback.
You are calling useQuery in an if statement, which violates the rules of hooks. Have a look at the
select
option, it should come in handy for data filtering