【问题标题】:React Native -- Possible to console.log in return()?React Native - 可以在 return() 中使用 console.log 吗?
【发布时间】:2017-04-27 14:45:45
【问题描述】:

我正在调试一个<View> 元素并希望确保正确返回一个变量。我如何console.log(element) 才能在控制台中查看它并确保它是正确的?

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    是的,有可能。

    return(
      <View>
        {console.log(element)}
      </View>
    )
    

    【讨论】:

      【解决方案2】:

      可能有很多技巧可以做到这一点,但我建议将您想要返回的内容存储在一个变量中,然后在返回之前记录您感兴趣的值,如下所示:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-24
        • 2019-05-02
        • 1970-01-01
        相关资源
        最近更新 更多