小编Tim*_*OES的帖子

React-Native this.setState()不起作用

我无法让反应本地人this.setState();工作.

当我运行该onUpdate方法时,我可以看到返回正确的JSON对象.

问题是当setState调用函数时没有任何反应,方法失败.它下面不再执行任何代码.它也不会在setState函数后重新渲染组件.

这是我的组件代码如下:

var App = React.createClass({

  getInitialState: function() {
    return {
      view: Login,
      menu: false,
    }
  },

  componentDidMount: function() {
    var self = this;
  },

  onUpdate: function(val){
    // val is verified as an object here when I log to console
    this.setState(val);
    // nothing runs here. The above line errors out the function
  },

  render: function () {
    if(this.state.view == 'Home'){
      this.refs.sideMenu.frontView = Home;
      return (
        <View style={styles.container} >
          {sideMenu}
        </View> …
Run Code Online (Sandbox Code Playgroud)

setstate react-native

5
推荐指数
2
解决办法
4万
查看次数

标签 统计

react-native ×1

setstate ×1