SolidJSS
SolidJSโ€ข4y agoโ€ข
9 replies
bigmistqke

storing a function inside a store

is it currently possible to store a function inside a store? it seems like they are being called immediately when I enter them in a store atm.

  const [state, setState] = createStore<{ test?: () => number }>({
    test: undefined,
  });

  const test = () => performance.now();
  setState('test', test);
  console.log(typeof test === typeof state.test) // logs false
  console.log(state.test, test); // logs 373409 () => performance.now()
  setTimeout(() => console.log(state.test, test()), 1000) // logs 373409 374409

https://playground.solidjs.com/anonymous/a8dcab94-f01e-48f0-9959-432cc6152de7
Quickly discover what the solid compiler will generate from your JSX template
Was this page helpful?