javascript - 不调用构造函数,但调用渲染

标签 javascript reactjs react-native

我有一些 React Native 代码,其中有以下 React 类:

import React, { Component } from 'react';
import { ScrollView, StyleSheet, TouchableHighlight, View, Text,  Platform } from 'react-native';
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux';

export default class MyList extends Component {
  constructor(props) {
      super(props);
      console.log("In constructor!");
      //some other code
  }

  componentWillMount() {
    console.log("In componentWillMount!");
  }

  render() {
    console.log("In render method!");
        return ( 
        <ScrollView
          horizontal={true} 
          showsHorizontalScrollIndicator={true}
          onLayout={this._onScrollViewLayout}
          onScroll={this._onScroll}
          ref={SCROLLVIEW_REF}
          scrollEventThrottle={8}
        > 
         //some other code
         </ScrollView>

        );
  }
}

问题是日志中只打印了这个:

 ReactNativeJS: In render method!

为什么我在 constructorcomponentWillMount 中看不到日志记录,它们应该在 render 方法之前调用?

编辑:

对于日志记录,我使用的是 react-native log-android

最佳答案

看起来问题可能出在 react-native log-android

我刚刚在 Google Chrome 上测试了您的代码,似乎运行良好。

也许这将有助于查明问题是否出在 react-native log-android 上? How to make console.log work in react native for android

关于javascript - 不调用构造函数,但调用渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46852481/

相关文章:

javascript - Ajax 没有将数据完全发布到 php 文件

javascript - 对象不支持此属性或方法 - 预期行为,但如何隐藏该消息?

react-native - 类型错误 : undefined is not an object (evaluating 'asset.scales' )

javascript - 多个事件创建动态+/-可编辑输入

javascript - 在空 RSS 提要后显示文本

javascript - 如何使用 React Native 从 api 加载数据

javascript - 为什么这些功能的工作方式不同?

css - 在 heroku 部署后,引导 css 规则应用于自定义规则?

javascript - 使用@react-native-firebase/messaging 收到通知后应用程序崩溃

javascript - 我怎样才能在 React Native Navigator 中禁用向后滑动