React Konva doesn't work with React 16.3 Context API
See original GitHub issueI am trying to use React 16.3 Context API based on render props with React Konva:
import React from "react";
import { Layer, Stage, Circle, Group, Line } from "react-konva";
const { Consumer, Provider } = React.createContext({ width: 0, height: 0 });
const ToolsLayer = () => (
<Consumer>
{({ height, width }) => (
<Layer>
<Group offsetY={-height} y={-42}>
<Line
points={[0, 0, width, 0, width, 42, 0, 42]}
closed
stroke="black"
/>
<Circle radius={11} fill="red" stroke="black" x={21} y={21} />
<Circle radius={11} fill="green" stroke="black" x={21 + 42} y={21} />
<Group />
</Group>
</Layer>
)}
</Consumer>
);
export default function Canvas({
width = window.innerWidth,
height = window.innerHeight
}) {
return (
<Provider value={{ width, height }}>
<Stage width={width} height={height}>
<ToolsLayer />
</Stage>
</Provider>
);
}
And I get runtime error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `ToolsLayer`.
Reproducible demo: https://codesandbox.io/s/2o9j1r6l30
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:26 (7 by maintainers)
Top Results From Across the Web
React v16.3.0: New lifecycles and context API
Version 16.3 introduces a new context API that is more efficient and supports both static type checking and deep updates. Note. The old...
Read more >Using a React Context With React-konva | by Colin Wren
To do this I started by building a context that I could then access, using the useContext hook in the components that needed...
Read more >Could not resolve dependency error peer react@"^16.8.0
While trying to install npm install , I am getting below error, could someone please advise, what is the best approach to resolve...
Read more >Apr 9, 2019
I am trying to use React 16.3 Context API based on render props with React Konva: import React from "react"; import { Layer,...
Read more >Getting started with react and canvas via Konva
Currently, react-konva is not supported in the React Native environment. Currently you can use all Konva nodes and shapes as React components and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Demo how to “bridge” contexts into
react-konva
tree:https://codesandbox.io/s/ykqw8r4r21
The usage of context api should probably be an example on the offical docs site, there is no mention there of this problem/pitfall and I only found this due to some google searches (which first led me in other directions).