S
SolidJS3mo ago
vikash

Console.log inside createEffect not printing...Even the setUser was called.

import { createEffect, createSignal, onMount } from "solid-js";
import { useSession } from "vinxi/http";

function getSession() {
return useSession({
password:
"my_secret_password_sajklhjkaojhjsdflkhasjdlfhsjkdfhajshflkjasdhfjalsdjfhlasjdhfjklashdfjsaflaskjfhsdflajhj",
});
}

const getUser = async () => {
const session = await getSession();
return session.data;
};
export default function Chat() {
const [user, setUser] = createSignal(null);

getUser().then((data) => {
setUser(data);
console.log("data : ", data);
console.log("user() : ", user());
});

createEffect(() => {
console.log("user : ", user());
});

return (
<main>
<h1>Chat</h1>
</main>
);
}
import { createEffect, createSignal, onMount } from "solid-js";
import { useSession } from "vinxi/http";

function getSession() {
return useSession({
password:
"my_secret_password_sajklhjkaojhjsdflkhasjdlfhsjkdfhajshflkjasdhfjalsdjfhlasjdhfjklashdfjsaflaskjfhsdflajhj",
});
}

const getUser = async () => {
const session = await getSession();
return session.data;
};
export default function Chat() {
const [user, setUser] = createSignal(null);

getUser().then((data) => {
setUser(data);
console.log("data : ", data);
console.log("user() : ", user());
});

createEffect(() => {
console.log("user : ", user());
});

return (
<main>
<h1>Chat</h1>
</main>
);
}
2 Replies
Madaxen86
Madaxen863mo ago
You need to call getUser in createAsync/createResource. https://docs.solidjs.com/solid-start/building-your-application/data-loading
vikash
vikashOP3mo ago
@Madaxen86 Thanks it worked, I need to read the docs now, as I am fairly new to solidjs.
Want results from more Discord servers?
Add your server