Carter
Carter
Explore posts from servers
SSolidJS
Created by Carter on 7/30/2024 in #support
How can I publish to github pages?
can I deploy to github with ssr turned off?
4 replies
SSolidJS
Created by Carter on 7/29/2024 in #support
How can i run some dom manip before rendering?
thank youuu
10 replies
SSolidJS
Created by Carter on 7/29/2024 in #support
How can i run some dom manip before rendering?
holy cow it works
10 replies
SSolidJS
Created by Carter on 7/29/2024 in #support
How can i run some dom manip before rendering?
idk how to do that
10 replies
SSolidJS
Created by Carter on 7/29/2024 in #support
How can i run some dom manip before rendering?
can you help me make it client only?
10 replies
SSolidJS
Created by Carter on 7/29/2024 in #support
How can i run some dom manip before rendering?
basically I have a localStorage value that determines if the site will be dark or light themed, but for some reason this code runs after it has already rendered leading to a flickering effect.
10 replies
SSolidJS
Created by Carter on 7/29/2024 in #support
How can i run some dom manip before rendering?
// @refresh reload
//
import { mount, StartClient } from "@solidjs/start/client";
const theme = JSON.parse(localStorage.getItem("theme")!!)
if (theme) {
document.body.classList.add("dark")
} else {
document.body.classList.remove("dark")
}
mount(() => <StartClient />, document.getElementById("app")!);
// @refresh reload
//
import { mount, StartClient } from "@solidjs/start/client";
const theme = JSON.parse(localStorage.getItem("theme")!!)
if (theme) {
document.body.classList.add("dark")
} else {
document.body.classList.remove("dark")
}
mount(() => <StartClient />, document.getElementById("app")!);
10 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
I see scripts assets and children where are scripts and assets located at?
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
No description
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
thank you so much that worked
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
okay
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
the issue is createEffect is called at the beginning once as well
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
well the logic in onMount should be called once, then for each change to the values we would persist it
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
when createEffect is called it persists the initial values and so nothing is displayed
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
No description
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
yes but now it's just persisting the initial values
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
oh I see what you're saying
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
how do I do that?
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
this right now works but the issue is I need to update the storage in the callback
47 replies
SSolidJS
Created by Carter on 7/27/2024 in #support
How can I persist state across page refreshes?
const [questionData, setQuestionData] = createSignal<FourCountryQuestionData>({
correctFlag: { name: '', continent: '', description: '', img: '' },
choices: []
});
const [score, setScore] = createSignal(0)

createEffect(() => {
console.log('createEffect')
})

onMount(() => {

console.log('onMount')

const storedQuestionData = localStorage.getItem("fourCountryQuestion");
if (storedQuestionData) {
console.log('getting questionData')
setQuestionData(JSON.parse(storedQuestionData));
} else {

setQuestionData(getRandomQuestionData())
localStorage.setItem("fourCountryQuestion", JSON.stringify(questionData()));
}
const storedScore = localStorage.getItem("score")
if (storedScore) {
console.log('getting score');
setScore(JSON.parse(storedScore))
} else {

setScore(0)
localStorage.setItem("score", JSON.stringify(score()))
}
})
return (
<div class="flex flex-row">

<div class="p-2 border rounded basis-1/2">
<img class="w-96 shadow-md border" src={questionData().correctFlag.img}></img>

<div class="grid grid-cols-2 gap-2 py-2">
<For each={questionData().choices}>{(flag, _) =>
<button class="p-2 border rounded" onclick={() => {
if (flag.name === questionData().correctFlag.name) {

setScore(score() + 1);
alert("right! current score: " + score())
setQuestionData(getRandomQuestionData())

localStorage.setItem("score", JSON.stringify(score()))
localStorage.setItem("fourCountryQuestion", JSON.stringify(questionData()))
} else {
alert('wrong!')
}
}}>
{flag.name}
</button>
}</For>

</div>

</div>

<div class="border p-4 rounded-full">
{score()}
</div>
</div>
const [questionData, setQuestionData] = createSignal<FourCountryQuestionData>({
correctFlag: { name: '', continent: '', description: '', img: '' },
choices: []
});
const [score, setScore] = createSignal(0)

createEffect(() => {
console.log('createEffect')
})

onMount(() => {

console.log('onMount')

const storedQuestionData = localStorage.getItem("fourCountryQuestion");
if (storedQuestionData) {
console.log('getting questionData')
setQuestionData(JSON.parse(storedQuestionData));
} else {

setQuestionData(getRandomQuestionData())
localStorage.setItem("fourCountryQuestion", JSON.stringify(questionData()));
}
const storedScore = localStorage.getItem("score")
if (storedScore) {
console.log('getting score');
setScore(JSON.parse(storedScore))
} else {

setScore(0)
localStorage.setItem("score", JSON.stringify(score()))
}
})
return (
<div class="flex flex-row">

<div class="p-2 border rounded basis-1/2">
<img class="w-96 shadow-md border" src={questionData().correctFlag.img}></img>

<div class="grid grid-cols-2 gap-2 py-2">
<For each={questionData().choices}>{(flag, _) =>
<button class="p-2 border rounded" onclick={() => {
if (flag.name === questionData().correctFlag.name) {

setScore(score() + 1);
alert("right! current score: " + score())
setQuestionData(getRandomQuestionData())

localStorage.setItem("score", JSON.stringify(score()))
localStorage.setItem("fourCountryQuestion", JSON.stringify(questionData()))
} else {
alert('wrong!')
}
}}>
{flag.name}
</button>
}</For>

</div>

</div>

<div class="border p-4 rounded-full">
{score()}
</div>
</div>
47 replies