Transitioning from pure frontend React to Next.js, I am currently working on implementing trpc calls to the backend. While this is a familiar process for me, it seems that the approach I've been using may not be appropriate in this case.
const [weight, setWeight] = useState<ChildWeightDataType[]>([]);
useEffect(() => {
if (activeChildId) {
const clientQuery = trpc.children.getWeight.useQuery({
childId: activeChildId
});
setWeight(clientQuery.data)
}
}, [activeChildId]);
It appears that the main issue lies in the fact that useQuery
is a hook, and using it within another hook is not allowed. What would be the correct pattern to follow in this scenario?