Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native -- Possible to console.log in return()?

I'm debugging a <View> element and want to ensure a variable is being returned correctly. How would I console.log(element) so I can view it in the console and ensure it's correct?

like image 978
Robert Schillinger Avatar asked Dec 12 '16 17:12

Robert Schillinger


2 Answers

Yes, it is possible.

return(
  <View>
    {console.log(element)}
  </View>
)
like image 177
Colin Avatar answered Nov 19 '22 05:11

Colin


There might be a number of tricks to do this, but I would advise storing what you want to return in a variable, and then log the value you are interested before the return, like this:

render() {
    let element = <MyElement></MyElement>
    console.log(element)
    let wrappingView = <View>{element}</View>

    return wrappingView;
} 
like image 29
martinarroyo Avatar answered Nov 19 '22 07:11

martinarroyo