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

React hooks incorrect scope in nested components #423

Closed
Tybot204 opened this issue Nov 2, 2019 · 1 comment
Closed

React hooks incorrect scope in nested components #423

Tybot204 opened this issue Nov 2, 2019 · 1 comment

Comments

@Tybot204
Copy link

Tybot204 commented Nov 2, 2019

React Konva: 16.10.1-0
React: 16.10.2

When using hooks inside nested Konva components, the hooks appear to lose the correct scope or context.

For a specific example, I am using some hooks from Material UI.

const MyComponent = () => {
  const theme = useTheme();

  // Prints the correct theme object I have configured in my app
  console.log(theme);

  return (
    <Stage>
      <Layer>
        <NestedComponent />
      </Layer>
    </Stage>
  );
};

const NestedComponent = () => {
  const theme = useTheme();

  // Prints the default theme, ignoring the config I have in the rest of the app
  console.log(theme)

  return <Text text="My Text" x={0} y={0} />;
};

This is not exclusive to Material UI hooks. I run into a similar error when using other libraries. It may be related to this issue.

@lavrton
Copy link
Member

lavrton commented Nov 4, 2019

react-konva is losing the context information from the tree above. At the current moment, I don't know any ways to automatically pass contexts into nested components. You have to "bridge" them manually.

For more info and a demo see here: #188

@lavrton lavrton closed this as completed Nov 4, 2019
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