Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class.contextType在H5端报错 #4539

Closed
calimanco opened this issue Sep 25, 2019 · 2 comments
Closed

Class.contextType在H5端报错 #4539

calimanco opened this issue Sep 25, 2019 · 2 comments
Labels
T-h5 Target - 编译到 H5 V-1 Version - 1.x

Comments

@calimanco
Copy link

问题描述
依据文档使用static contextType = CounterContext或MyClass.contextType = MyContext这两种使用方式都会报错,只有使用的页面会报错,不使用的没问题。

TypeError: Cannot read property 'store' of null
    at WrappedComponent.Connect(GoodsDetail) [as constructor] (index.esm.js?94e6:496)
    at new WrappedComponent (index.esm.js?eb04:2343)
    at mountComponent (index.esm.js?eb37:1715)
    at ComponentWrapper.init (index.esm.js?eb37:2144)
    at createElement (index.esm.js?eb37:1401)
    at mountChild (index.esm.js?eb37:1466)
    at mountVNode$1 (index.esm.js?eb37:1456)
    at createElement (index.esm.js?eb37:1406)
    at patch (index.esm.js?eb37:948)
    at updateComponent (index.esm.js?eb37:1858)

复现步骤

  1. 在context.js里写export const PageControllerContext = Taro.createContext({} as any)
  2. 在页面中使用,并将页面connect到redux导出。
    顺便一提,ts这里会报错
Property 'Consumer' is missing in type 'Taro.Context<any>' but required in type 'React.Context<any>'.
  1. 编译H5通过
  2. 打开页面报上面的错误

期望行为
不要报错,正常显示页面

报错信息

见上

系统信息
Taro CLI 1.3.19 environment info:
System:
OS: macOS 10.14.6
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
npmPackages:
@tarojs/async-await: 1.3.19 => 1.3.19
@tarojs/components: 1.3.19 => 1.3.19
@tarojs/plugin-babel: 1.3.19 => 1.3.19
@tarojs/plugin-csso: 1.3.19 => 1.3.19
@tarojs/plugin-sass: 1.3.19 => 1.3.19
@tarojs/plugin-uglifyjs: 1.3.19 => 1.3.19
@tarojs/redux: 1.3.19 => 1.3.19
@tarojs/redux-h5: 1.3.19 => 1.3.19
@tarojs/router: 1.3.19 => 1.3.19
@tarojs/taro: 1.3.19 => 1.3.19
@tarojs/taro-alipay: 1.3.19 => 1.3.19
@tarojs/taro-h5: 1.3.19 => 1.3.19
@tarojs/taro-swan: 1.3.19 => 1.3.19
@tarojs/taro-tt: 1.3.19 => 1.3.19
@tarojs/taro-weapp: 1.3.19 => 1.3.19
@tarojs/webpack-runner: 1.3.19 => 1.3.19
eslint-config-taro: 1.3.19 => 1.3.19
eslint-plugin-taro: 1.3.19 => 1.3.19
nerv-devtools: ^1.4.5 => 1.4.5
nervjs: ^1.4.5 => 1.4.5
react: ^16.9.0 => 16.9.0
stylelint-config-taro-rn: 1.3.19 => 1.3.19
stylelint-taro-rn: 1.3.19 => 1.3.19

@taro-bot
Copy link

taro-bot bot commented Sep 25, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@aoarashi1988
Copy link

检查一下,是否在引用组件中使用了constructor构造函数,那会重置this.context

@ZakaryCode ZakaryCode added T-h5 Target - 编译到 H5 V-1 Version - 1.x labels Jan 15, 2022
@ZakaryCode ZakaryCode moved this to Done in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-h5 Target - 编译到 H5 V-1 Version - 1.x
Projects
Archived in project
Development

No branches or pull requests

3 participants