Generate random numbers serverside and don't regenerate on hydration

I'm trying to generate a list of random numbers for a skeleton loader, and I've found a solution, but it does not feel like the right way to do this.
const [randomsResource] = createResource(() => [""], {
initialValue: [
"3".repeat(5 + Math.floor(Math.random() * 6)),
"a".repeat(7 + Math.floor(Math.random() * 20)),
"a".repeat(15 + Math.floor(Math.random() * 10)),
"a".repeat(15 + Math.floor(Math.random() * 10)),
"a".repeat(15 + Math.floor(Math.random() * 10)),
],
ssrLoadFrom: "initial",
});
const randoms = randomsResource();

return <div>{randoms[0]</div> ...
const [randomsResource] = createResource(() => [""], {
initialValue: [
"3".repeat(5 + Math.floor(Math.random() * 6)),
"a".repeat(7 + Math.floor(Math.random() * 20)),
"a".repeat(15 + Math.floor(Math.random() * 10)),
"a".repeat(15 + Math.floor(Math.random() * 10)),
"a".repeat(15 + Math.floor(Math.random() * 10)),
],
ssrLoadFrom: "initial",
});
const randoms = randomsResource();

return <div>{randoms[0]</div> ...
Is there a better method to only execute something server-side, and send that to the client?
2 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Razboy20
Razboy20OP2y ago
No; I want to see whether there is a way to do it without resources
Want results from more Discord servers?
Add your server