【问题标题】:KonvaJs example does not work once i updated mobx 5一旦我更新了 mobx 5,KonvaJs 示例就不起作用
【发布时间】:2020-04-09 17:59:01
【问题描述】:

我正在尝试在该 KonvaJs 示例上进行开发:https://konvajs.org/docs/sandbox/Window_Frame_Designer.html

克隆存储库后,一切正常。但是,一旦我将 mobx 从 4.3.1 更新到 5.15.0,就会出现该错误;

错误:MobX 注入器:商店“商店”不可用!确保它是由某个 Provider 提供的

谁能帮我解决这个问题。 谢谢。

【问题讨论】:

    标签: 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      相关资源
      最近更新 更多