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

[微信小程序]mobx的computed(getter)属性在条件渲染下无效 #4667

Closed
drewxiuxiuxiu opened this issue Oct 23, 2019 · 2 comments
Closed
Assignees

Comments

@drewxiuxiuxiu
Copy link

drewxiuxiuxiu commented Oct 23, 2019

问题描述

let local = useLocalStore(() => ({
    get foo() {
       return 'bar'
    }
  }))

return (
    <View>
        { local.foo === 'bar' && <SomeView /> }
    </View>
)

在此情况下SomeView永远无法渲染. 微信调试工具中可见store中并没有foo属性.

H5正常.

复现步骤
[复现问题的步骤]
如上

期望行为
[这里请用简洁清晰的语言描述你期望的行为]
与H5相同

报错信息


系统信息

Taro CLI 1.3.21 environment info:
System:
OS: macOS 10.14.6
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.15.0 - ~/.nvm/versions/node/v8.15.0/bin/node
Yarn: 1.12.3 - ~/.nvm/versions/node/v8.15.0/bin/yarn
npm: 6.11.2 - ~/.nvm/versions/node/v8.15.0/bin/npm
npmPackages:
@tarojs/async-await: ^1.3.19 => 1.3.21
@tarojs/components: 1.3.21 => 1.3.21
@tarojs/mobx: 1.3.21 => 1.3.21
@tarojs/mobx-h5: 1.3.21 => 1.3.21
@tarojs/mobx-rn: 1.3.21 => 1.3.21
@tarojs/plugin-babel: 1.3.21 => 1.3.21
@tarojs/plugin-csso: 1.3.21 => 1.3.21
@tarojs/plugin-sass: 1.3.21 => 1.3.21
@tarojs/plugin-uglifyjs: 1.3.21 => 1.3.21
@tarojs/rn-runner: 1.3.21 => 1.3.21
@tarojs/router: 1.3.21 => 1.3.21
@tarojs/taro: 1.3.21 => 1.3.21
@tarojs/taro-alipay: 1.3.21 => 1.3.21
@tarojs/taro-h5: 1.3.21 => 1.3.21
@tarojs/taro-swan: 1.3.21 => 1.3.21
@tarojs/taro-tt: 1.3.21 => 1.3.21
@tarojs/taro-weapp: 1.3.21 => 1.3.21
@tarojs/webpack-runner: 1.3.21 => 1.3.21
eslint-config-taro: 1.3.21 => 1.3.21
eslint-plugin-taro: 1.3.21 => 1.3.21
nerv-devtools: ^1.4.0 => 1.5.1
nervjs: ^1.4.0 => 1.5.1
stylelint-config-taro-rn: 1.3.21 => 1.3.21
stylelint-taro-rn: 1.3.21 => 1.3.21
npmGlobalPackages:
typescript: 3.6.2

补充信息
[可选]

@taro-bot
Copy link

taro-bot bot commented Oct 23, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@nanjingboy
Copy link
Member

@drewxiuxiuxiu 不要在 JSX 中对可观察对象进行引用,这样修改代码:

let local = useLocalStore(() => ({
    get foo() {
       return 'bar'
    }
  }))


const { foo } = local

return (
    <View>
        { foo === 'bar' && <SomeView /> }
    </View>
)

具体描述参见:http://taro-docs.jd.com/taro/docs/mobx.html#observer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants