Disable force update of properties of Konva nodes
See original GitHub issueCurrently, react-konva
works VERY strictly in terms of how it updates props of nodes.
When a component is updated react-konva
will change all attributes of a node exactly how it is defined in render()
function. In many cases, it gives unexpected behavior for new users and it requires additional work to sync state of the app with the props of nodes.
The most common issue is drag&drop:
<Circle
draggable
x={10}
y={10}
radius={50}
fill={this.state.fill}
onDragEnd={() => {
this.setState({ fill: getRandomColor() })
}}
/>
At first, the component looks good. But it will not work, as expected. Because on dragend
the position will be reseted back to {10,10}
(as defined in render). I think most of the users expect no to see that reset.
My proposal is to add useStrictMode
function. By default react-konva will NOT use strict mode. I think it will work better for the most of the apps. If strict updates are still required a user can do this:
import { useStrictMode } from 'react-konva';
useStrictMode(true);
In non-strict-mode react-konva
wil update properties of the node only if they changed in render() function. That is similar how react-dom
updates DOM nodes.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top GitHub Comments
Also struggling with a regression for the last few hours, eventually did a bisect to track it down to a
react-konva
upgrade and led me here.@bmoquist sorry for that situation. Will be more careful next time. Also soon I will add more info about
strict
mode into the documentation.