S
SolidJSjoalisonx

createResource returns undefined

Hello, goodnight everyone. Im having a problem using createResource. This function returns me undefined whenever I try to log it (console.log(data())). I tested to see that this wasn't an issue in my API by logging the response in the fetcher function and everything was as expected. The strangest thing is that I can normally render the result of this resource even though it is undefined.
const [data] = createResource(getGames);
<For each={data()}>{game => (<Game {...game}/>)}</For>
const [data] = createResource(getGames);
<For each={data()}>{game => (<Game {...game}/>)}</For>
J
joalisonx271d ago
R
REEEEE271d ago
The resource is undefined initially lf you are console logging in a non reactive scope, like outside the JSX or not in an effect, it will log undefined and won't react to when the resource resolves an example:
const App = () => {
const [data] = createResource(getGames);
console.log(data()) <------ will log undefined and not update

createEffect(() => {
console.log(data()) <----- will log undefined first, and then after the resource resolves/finishes fetching it will print the data
})

return(
<For each={data()}>{game => (<Game {...game}/>)}</For>
)
}
const App = () => {
const [data] = createResource(getGames);
console.log(data()) <------ will log undefined and not update

createEffect(() => {
console.log(data()) <----- will log undefined first, and then after the resource resolves/finishes fetching it will print the data
})

return(
<For each={data()}>{game => (<Game {...game}/>)}</For>
)
}
J
joalisonx271d ago
Oh I didn't know that. Thank you 👏
S
syahzuan185d ago
Just stumbled upon the same issue. Very helpful to me as well! Thanks!
Want results from more Discord servers?
Add your server
More Posts
Suspense doesn't seem to work with ContextProviderhey, so recently I noticed, If I use `createResource(fetch)` and then put `<Suspense fallback={<PlLayout for layout groupTo make a layout for a route you need to make a .tsx file with the same name as the parent folder. BHow to deploy an solid js app myselfHi all, good morning. Does anyone have a resource (blog post, tutorial, vídeo, etc) teaching how to SVG A elements not created correctlyWhen using an <a> element with <Show> or <For> inside an inline SVG element, we get the namespace wrHow to add events for scrolling like React? (with solid-qurey)Hi, I've only been dealing with React projects and I'm practicing Solid-js. `createResource` offerWhat's the best way to create multiple layouts that only some routes use?I need to have multiple layouts. I'd like some pages to use different layouts, rather than a single Looking for best way to re-validate route data after some arbitrary amount of time.Hi all, good morning/afternoon/night. So, i have a routed component with nested routes that share a How to stop VS Code from erroring with `Cannot find name 'React'.ts(2304)`?VS Code is complaining with `Cannot find name 'React'.ts(2304)` but I am not using React at all. I hHow should I use createRouteData``` export function routeData({ params, location }: RouteDataArgs) { return createServerData$( How can I access a store from the parent context from inside of a nested context?I am trying to access the WebsocketContext from inside of the DataStreamContext, in order to send ouUsing `createResource` without triggering suspenseI'm trying to use `createResource` without triggering Suspense. I realised that `data.latest` still `<A>` from `solid-start` is slow on Android. How to debug performance?So, on my detail page I have a button ```jsx import { A } from 'solid-start'; const Detail = () =>