TanStackT
TanStack4y ago
12 replies
worthy-azure

React query populate initial state

Hello all, I have a question I am trying to populate a state when the component first renders, using react-query. I am able to do it using useEffect, but wondering if there's a way to do it without it. currently I have something like this, I have also tried something like this as well. Maybe I am missing something basic?
 const [selectedCountry, setSelectedCountry] = useState(!isLoading && labels[3]?.label); 
image.png
Was this page helpful?