React Konva provides declarative and reactive bindings for integrating the Konva 2D canvas framework into React applications. It allows developers to use Konva's rich set of shapes, layers, and stage components as standard React components, enabling a familiar declarative JSX syntax for canvas drawing. The library is currently at version 19.2.3, frequently releasing patch and minor updates to ensure compatibility with the latest React and Konva versions. Its primary differentiator is leveraging React's component model and data flow for high-performance canvas rendering, abstracting away direct DOM manipulation. It is built on top of the Konva framework, meaning users primarily need to understand Konva's API and concepts to effectively use React Konva.
npm install react-konvaVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a basic Konva stage with a layer, a text element, and a clickable colored rectangle using React state and event handlers.
Use a different library specifically designed for React Native canvas or drawing if targeting mobile native platforms.
Enable strict mode globally with `useStrictMode(true)` or per-component with the `_useStrictMode` prop if you need all properties to always reflect the render function's state, especially when dealing with external manipulations or complex animations.
Ensure your project uses `react@^19.2.0` and `react-dom@^19.2.0` when using react-konva v19.x.
When using Konva v10, ensure react-konva is at least v19.0.8. Check your package.json for peer dependency ranges and update accordingly.
Update to react-konva v19.0.6 or newer to resolve issues with double event attachments when using React's Strict Mode.
Ensure all children within `<Stage>` and `<Layer>` are valid React-Konva components (e.g., `<Rect>`, `<Circle>`) and not raw Konva instances or other non-renderable objects.
All visual Konva components (e.g., `<Rect>`, `<Circle>`, `<Text>`) must be nested inside a `<Layer>` component, which in turn is a child of the `<Stage>` component.
Ensure you access `ref.current` within a `useEffect` hook with an empty dependency array (`[]`) to guarantee the component is mounted and the ref has been assigned to the Konva node instance.
For SSR, conditionally render the `<Stage>` component only on the client-side, provide default dimensions, or use a client-only rendering approach for the canvas component if browser globals are required for initial sizing.