I’m learning nextjs coming from pure frontend react.
And trying to understand how to implement using trpc calls to the backend.
This is something I’m used to doing, but it is not the correct way in this instance.
const [weight, setWeight] = useState<ChildWeightDataType[]>([]);
useEffect(() => {
if(activeChildId){
const clientQuery = trpc.children.getWeight.useQuery({childId:activeChildId});
setWeight(clientQuery.data)
}
}, [activeChildId]);
I guess the issue here is that useQuery is a hook, so I’m not allowed to use it inside another hook. What is the correct pattern here?
You just use the useQuery and deconstruct it in order to get the data property.
const {data} = trpc..useQuery()
You can then useEffect to listen to changes in data and do the effect you want
1