2017-10-20 82 views
2

我有一些阵营本地代码中,我有以下反应类:构造不叫,但渲染被称为

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

+0

'Constructor'和'componentWillMount'只被调用一次(当组件被挂载时)。之后,每次更新组件时,都不会调用这些方法,但会调用“render”。你是否说这些方法即使在组件安装时也不会被调用? –

+0

好的,但仍然会出现这些方法的日志记录,对吧?日志记录是一个中间件,在调用构造函数时处于范围内,对吗? – octavian

回答