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

componentWillMount, componentWillReceiveProps and render being called twice times #16806

Closed
Kottidev opened this issue Nov 13, 2017 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@Kottidev
Copy link

Kottidev commented Nov 13, 2017

Is this a bug report?

Yes

Bug

I created new app with react-native-init ,

and i added log to know it's a bug from react-native or from my code ;

export default class App extends PureComponent<{}> {
  componentWillMount() {
    console.log('componentWillMount');
  }
  componentDidMount() {
    console.log('componentDidMount');
  }
  componentWillReceiveProps() {
    console.log('componentWillReceiveProps');
  }
  render() {
    console.log('render')
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          BUG WITH React Native!
        </Text>
      </View>
    );
  }
}

This is the result of log :

2017-11-13 09:37:41.369 [info][tid:com.facebook.react.JavaScript] componentWillMount
2017-11-13 09:37:41.368865+0100 myapp[14909:120213] componentWillMount
2017-11-13 09:37:41.369 [info][tid:com.facebook.react.JavaScript] render
2017-11-13 09:37:41.369192+0100 myapp[14909:120213] render
2017-11-13 09:37:41.378 [info][tid:com.facebook.react.JavaScript] componentDidMount
2017-11-13 09:37:41.378381+0100 myapp[14909:120213] componentDidMount

Environment

Environment:

OS: macOS Sierra 10.12.6
Node: 6.11.2
Yarn: 1.3.2
npm: 5.5.1
Watchman: 4.7.0
Xcode: Xcode 9.1 Build version 9B55
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: 16.0.0 => 16.0.0
react-native: 0.50.3 => 0.50.3

Target Platform: iOS (10.3)

@Sommerfeld
Copy link

Sommerfeld commented Nov 14, 2017

The log just appears twice.

App.js

let i = 0;

export default class App extends PureComponent<{}> {
  componentWillMount() {
    console.log('componentWillMount', i++);
  }
  componentDidMount() {
    console.log('componentDidMount', i++);
  }
  componentWillReceiveProps() {
    console.log('componentWillReceiveProps', i++);
  }

  render() {
    console.log('render', i++);
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>NOT a bug in React Native!</Text>
      </View>
    );
  }
}

Output

2017-11-14 11:06:02.299 [info][tid:com.facebook.react.JavaScript] 'componentWillMount', 0
2017-11-14 11:06:02.298924+0100 test[11971:603622] 'componentWillMount', 0
2017-11-14 11:06:02.299 [info][tid:com.facebook.react.JavaScript] 'render', 1
2017-11-14 11:06:02.299328+0100 test[11971:603622] 'render', 1
2017-11-14 11:06:02.305 [info][tid:com.facebook.react.JavaScript] 'componentDidMount', 2
2017-11-14 11:06:02.305171+0100 test[11971:603622] 'componentDidMount', 2

@Kottidev
Copy link
Author

@Sommerfeld thanks

@Kottidev
Copy link
Author

@hramos we can close this issue

@alizbazar
Copy link

Why does the log appear twice? What is the best way to prevent this?

@woowalker
Copy link

OK, i face this problem right now, and i found that because our android developer change some native code, seems android developer code new another Activity!!!!
hope that helpful

@facebook facebook locked as resolved and limited conversation to collaborators Nov 14, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Nov 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants