Recently I have been exploring solid.js and I am not clear about the rendering mechanism
for data querying, I am using Tanstack query, and inside the component, I am calling the same function fetchUserData but what createQuery I am storing into a state variable and rendering the data into UI, which is working. But when I directly distract the data from the state and try to render it into UI and now it is not working. I am really not clear with the concept
import { createQuery } from "@tanstack/solid-query";
const fetchUserData = () => createQuery(()=> ({
queryKey: ['users'],
queryFn : async () => {
const res = await fetch(`https://jsonplaceholder.typicode.com/users`)
return await res.json()
}
}))
const Home = () => {
const state = fetchUserData()
const {data} = fetchUserData()
return (
<div>
{/* working */}
{
state?.data?.map(item => <h1> {item.name} </h1>)
}
{/* not working */}
{data?.map(item => <h1> {item.name} </h1> )}
</div>
);
};
export default Home;