SolidJSS
SolidJSโ€ข2y agoโ€ข
12 replies
Strange

Stores, context, & reactivity

Hey crew, got another question for y'all

I have the following code:

export function MemoryProvider(props: { children: JSX.Element }) {
  const audioContext = new window.AudioContext();
  const masterAnalyser = audioContext.createAnalyser();

  const [panelsStore, setPanelsStore] = createStore({
    panels: [] as PanelFunction[]
  });

  const memory = {
    audioContext,
    masterAnalyser,

    panels: panelsStore.panels, // This line is the problem
    addPanel(NewPanel: PanelFunction) {
      console.log("Adding a panel...");
      return setPanelsStore("panels", panelsStore.panels.length, () => NewPanel);
    },
    removePanel(OldPanel: PanelFunction) {
      console.log("Removing a panel...");
      return setPanelsStore("panels", panelsStore.panels.filter((panel) => panel !== OldPanel));
    },

    mousePosition: useMousePosition()
  };

  return (
    <MemoryContext.Provider value={memory}>
      {props.children}
    </MemoryContext.Provider>
  );
}


And I am getting a warning from solid lint (reactivity) stating that panelsStore.panels should be wrapped in a useEffect or used inside of JSX or else the updates will be ignored. I'm not entirely sure what to do here, because the memory object is being passed into the value for the context provider.
Was this page helpful?