<For> throws Cannot access 'product2' before initialization
I am wrapping my component in a show on product().name and have used debugger to step through and verify the Component is not run until product().name is set, yet I am getting this error originating from the <For> below:
product().imgs are loaded and can never reach a break point within the For child function so breaks before I can check there. Any ideas?
4 Replies
I would assume
product()
is a resource and so the error comes from the fact that it is initially undefined
(becomes undefined.imgs
which is the error). Resources being initially undefined
is natural.
The workaround is as simple as:
product()?.imgs
Hmm I had to do product() && and it at least moved through the error but nothing loads just goes to my fallback even though the data is there on the server side before responding to the client on initial request...
product is a signal set on initial render from result of a create async/ route data. I inject it in context and import it into this file and the parent like this:
(layout).jsx:
(layout)/(page)/product/[id].jsx
Product.jsx
ideally that initialProduct wouldn't work given the nature of createAsync (createResource)'s non-blocking behavior
Yeah I had to get rid of that and just use the data() from createAsync(). I guess if I want to destructure data() and use in context I should just use a store?