bsky
bsky

Reputation: 20222

Constructor is not called, but render is called

I have some React Native code within which I have the following React class:

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>

        );
  }
}

The problem is that only this is printed in the logs:

 ReactNativeJS: In render method!

Why can I not see the logging in either the constructor or componentWillMount, which should be called before the render method?

EDIT:

For logging, I'm using react-native log-android.

Upvotes: 2

Views: 295

Answers (1)

darthaditya
darthaditya

Reputation: 124

Looks like the problem might be with react-native log-android

I just tested your code on Google Chrome and that seems to be working just fine.

Maybe this will help pinpoint whether the issue is with react-native log-android? How to make console.log work in react native for android

Upvotes: 1

Related Questions