SolidJSS
SolidJSโ€ข12mo agoโ€ข
10 replies
hyperknot

How do I best have createMemo in a store?

I'm used to MobX, where I can put a @computed on any method in a store.

In Solid, how do I best replicate this?

If I do this:

export class Chat {
  state: ChatState
  private setState: SetStoreFunction

  isActive: () => boolean

  constructor() {
    const [state, setState] = createStore({
     //...
    })

    this.state = state
    this.setState = setState
    
    // Create memo after state is initialized
    this.isActive = createMemo(() => uiStore.state.activeDocumentID === this.state.uuid)
  }


Then I get the error:
computations created outside a
createRoot
or
render
will never be disposed

I'd love to "cache" this value. There are thousands of documents and only one can be active at any time. How would you best structure the store for this, so that the comparisons cached/memoed?
Was this page helpful?