SolidJSS
SolidJS12mo ago
52 replies
Jason.json

useContext returns undefined

Hi there! I am making a game launcher wich looks like an OS in frutiger aero style with Solid JS. I have a ContextProvider wrapping my whole app like so:

 render(
    () => (
      <WindowManagerProvider>
        <App />
      </WindowManagerProvider>
    ),
    document.getElementById("root")!
  );


And i use the context inside a DraggableWindow.tsx here:

export default function DraggableWindow(props: DraggableWindowProps) {
  const [position, setPosition] = createStore({ x: 100, y: 100 });
  let ref: HTMLDivElement | undefined;

  const context = useWindowManagerContext()!;
  // rest of the code...
  return (
    // parent code
    {props.children}
    // parent code
  );
}


The context works inside the DraggableWindow, but when I try to use it in it's children it returns
undefined
. I use components to spawn a window with content.
image.png
Was this page helpful?