[solved] createEffect signal is Undefined

I can't seem to figure out why the signal user is not updating (the output near Profile). The signal does get populated. Clues? Tutorial link with real-world example? Thanks.
35 Replies
dmayo2
dmayo2OP2y ago
Might be createResource? Not quite. Suspense?
Alex Lohr
Alex Lohr2y ago
user is directly used in the return statement, right after profile. Suspense would help if you used createResource to take the supabase call into solid's reactive system. user() initially returns []
dmayo2
dmayo2OP2y ago
Thanks. Isn't that what the const currentUser is doing? The return of supabase is put into setUser(data). I thought that was "bringing the supabase call into solid's reactive system". I'm obviously missing something in my thought process. I also tried createResource with and without <Suspense and with and without <Show
dmayo2
dmayo2OP2y ago
This is close. In the browser console it says Unrecognized value. Skipped inserting > Object and the object is the data that's returned, but the output next to the <h2>Profile is still not rendered, not even the Loading... (or maybe it's so fast I don't see it).
dmayo2
dmayo2OP2y ago
Well, loading is spelled wrong. Upon fixing that, I do see the Loading... appear for a second or two, then it goes away, and replaced by an empty string. So, if the output of the Resource Signal is just currentUser() the page will render, and the Loading... flashes, but no output. If I try currentUser().user.email the page won't render as that throws an error of currentUser() is undefined Getting closer, just missing something.
dmayo2
dmayo2OP2y ago
Ok, this works, but I need to target one node, not the entire data stream
dmayo2
dmayo2OP2y ago
REEEEE
REEEEE2y ago
You would do currentUser()?.user.email or in a Show
<Show when={currentUser()} fallback={<> Loading... </>}>
<> Profile | {currentUser()!.user.email} </>
</Show>
<Show when={currentUser()} fallback={<> Loading... </>}>
<> Profile | {currentUser()!.user.email} </>
</Show>
dmayo2
dmayo2OP2y ago
Thanks. Still getting currentUser() undefined
REEEEE
REEEEE2y ago
How are you using it?
dmayo2
dmayo2OP2y ago
Many trials and errors.
dmayo2
dmayo2OP2y ago
I'm having a serious brain fart. I can the entire object to print out, but I can't seem to just extract the email value. This shot is with JSON.stringify on the await function.
REEEEE
REEEEE2y ago
how are you using currentUser() in the JSX?
dmayo2
dmayo2OP2y ago
currently (iteration #3,456)
REEEEE
REEEEE2y ago
you need to call currentUser in the Show same with the effect
dmayo2
dmayo2OP2y ago
I cleaned it up. As is, it's still outputting the entire object.
REEEEE
REEEEE2y ago
This did not work?
dmayo2
dmayo2OP2y ago
no, it's killing me.
REEEEE
REEEEE2y ago
it's outputting the entire object because you're not accessing anything from the object.
<> {currentUser()?.user.email} </>
<> {currentUser()?.user.email} </>
dmayo2
dmayo2OP2y ago
true. but that's been my iterations-- dot notation, brackets, etc. I can't seem to target just the email: data:user:email
REEEEE
REEEEE2y ago
<> {currentUser()?.data.user.email} </>
<> {currentUser()?.data.user.email} </>
Didn't notice there was a data object
dmayo2
dmayo2OP2y ago
REEEEE
REEEEE2y ago
and change the when to when={currentUser()}
dmayo2
dmayo2OP2y ago
REEEEE
REEEEE2y ago
you're also returning a string from fetchUser not an object remove JSON.stringify
dmayo2
dmayo2OP2y ago
Can I buy you a beer.
REEEEE
REEEEE2y ago
haha
dmayo2
dmayo2OP2y ago
I don't think I've ever seen the ? before after the()
REEEEE
REEEEE2y ago
It's a typescript thing Called optional chaining
dmayo2
dmayo2OP2y ago
I'm specifically using the js version when I installed with npm
REEEEE
REEEEE2y ago
Well technically you don't need it in this case the solution wasn't because of the ?
dmayo2
dmayo2OP2y ago
It's 5pm somewhere. Thank you very much.
REEEEE
REEEEE2y ago
No problem
thiccaxe
thiccaxe2y ago
Not in typescript, it is in JavaScript. Related !. is typescript for disabling nullish checking
REEEEE
REEEEE2y ago
Ah thank you for correcting me Mixed it up
Want results from more Discord servers?
Add your server