Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context not available in <Stage> children #218

Closed
kresli opened this issue May 9, 2021 · 2 comments
Closed

context not available in <Stage> children #218

kresli opened this issue May 9, 2021 · 2 comments

Comments

@kresli
Copy link

kresli commented May 9, 2021

import "./styles.css";
import { Stage, Container } from "react-pixi-fiber";
import { createContext, FunctionComponent, useContext } from "react";

const Context = createContext<{ title: string }>(
  (null as any) as { title: string }
);

const Wrapper: FunctionComponent = ({ children }) => {
  const context = useContext(Context);
  // following will throw
  if (!context) throw new Error("context not defined"); 
  return <Container>{children}</Container>;
};

export default function App() {
  return (
    <Context.Provider value={{ title: "hello" }}>
      <div className="App">
        <Stage>
          <Wrapper />
        </Stage>
      </div>
    </Context.Provider>
  );
}

I would expect context will be available in Wrapper.

Additional info

  • react-pixi-fiber version: 1.0.0-beta.9
  • React version: 17.0.2
  • ReactDOM version: 17.0.2
  • PixiJS version: 6.0.2
@kresli kresli changed the title context not available in stage's children context not available in <Stage> children May 9, 2021
@kresli
Copy link
Author

kresli commented May 9, 2021

I think this is an issue of react not react-pixi-fiber
facebook/react#17275
feel free to close the ticket

@michalochman
Copy link
Owner

Hi @kresli, yes, this is a react issue. Contexts are not shared between different renderers. See #93 for workarounds. Also mentioned in #145.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants