SolidJSS
SolidJSโ€ข3y agoโ€ข
2 replies
Razboy20

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> ...


Is there a better method to only execute something server-side, and send that to the client?
Was this page helpful?