-
-
Notifications
You must be signed in to change notification settings - Fork 180
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 accessible inside Stage #281
Comments
Duplicate #77 Unfortunately customer reconcilers cannot access its parent Context. This is a well known React issue, however you can bypass this with a simple Context Bridge component like this: // context-bridge
const ContextBridge = ({ children, Context, render }) => {
return (
<Context.Consumer>
{(value) => render(<Context.Provider value={value}>{children}</Context.Provider>)}
</Context.Consumer>
);
};
// stage
import { Stage as PixiStage } from '@inlet/react-pixi';
const Stage = ({ children, ...props }) => {
return (
<ContextBridge
Context={RecoilContext}
render={(children) => <PixiStage {...props}>{children}</PixiStage>}
>
{children}
</ContextBridge>
);
}; |
Now that is a useful trick |
Typescript version for future readers export default function ContextBridge<T>(props: {
children: React.ReactNode
Context: React.Context<T>
render: (children: React.ReactNode) => JSX.Element
}): JSX.Element {
const Context = props.Context
const result = <Context.Consumer>
{(value) => props.render(<Context.Provider value={value}>{props.children}</Context.Provider>)}
</Context.Consumer>
return result
} |
If you try to make to have a prop |
I am trying to access a context where my game data will be stored. However this context is not accessible from children wrapped inside the
Stage
Component.Setup:
Console log works fine here:
But this doesn't work:
Also I have never used PixiJS before and this is a first of using React in combination with TypeScript. If it is not possible to store game data with a context, is there a preffered way?
Additional info
@inlet/react-pixi
version: 6.1.1React
version: 17.0.1ReactDOM
version: 17.0.1PIXI
version: 5.3.8The text was updated successfully, but these errors were encountered: