【问题标题】:KonvaJs example does not work once i updated mobx 5一旦我更新了 mobx 5,KonvaJs 示例就不起作用
【发布时间】:2020-04-09 17:59:01
【问题描述】:
【问题讨论】:
标签:
reactjs
mobx
mobx-react
konvajs
react-konva
【解决方案1】:
看起来 mobx-react 正在使用 React 上下文将 store 传递给组件。
但是 React Context 不能自动用于自定义反应渲染器(例如 react-konva)。欲了解更多信息,请参阅:https://github.com/konvajs/react-konva/issues/188
作为解决方法,您只需在 <Stage> 组件内“桥接”存储:
<Stage
width={this.state.width}
height={height}
ref={ref => {
this.stageRef = ref;
}}
onClick={this.handleClick}
>
<Provider store={this.props.store}>
<Layer scaleX={scale} scaleY={scale} y={20} x={20}>
<Section
section={root.sections[0]}
x={root.frameSize}
y={root.frameSize}
/>
<Sash
width={root.width}
height={root.height}
size={root.frameSize}
/>
<Metrics />
</Layer>
</Provider>
</Stage>
演示:https://codesandbox.io/s/frame-editor-update-t7nxw