【问题标题】:Out of memory onPress TouchableOpacity, React native内存不足 onPress TouchableOpacity, React native
【发布时间】:2018-11-18 02:07:11
【问题描述】:

我有一个组件,当满足某些条件时我会显示一个按钮(基于组件状态)

{
      this.state.inputTag !== null && this.state.inputTagFocused ? (
        <TouchableOpacity 
          style = {{backgroundColor : Colors.primary, padding : 15, paddingBottom : 5, paddingTop : 5, borderRadius: 2}}
          onPress = {this.handleAddTags}
        >
          <Text style = {{fontFamily : Fonts.primary, color : Colors.white}}>Add</Text>
        </TouchableOpacity>
      ) : null
    }

使用 TextInput 组件我正在像这样更新状态

<TextInput
  style = {{ borderBottomColor : Colors.grey, padding : 15, paddingLeft :0, paddingRight : 0, marginRight : 15}}
  onChange = {(text)=> this.setState({inputTag : text})}
  onFocus = {() => this.setState({inputTagFocused : true})}
  placeholderTextColor = {Colors.grey}
  ref = {(tags) => {this.tags = tags}}
  underlineColorAndroid = 'transparent'
  placeholder = 'Add Tags'
  returnKeyType = 'done'
  multiline = {false}
/>

一切似乎都正常,除了当我按下添加按钮时,整个应用程序崩溃,几分钟后我收到“内存不足”的错误。

是什么导致了这个问题?我该如何解决?

完整代码可见here

【问题讨论】:

    标签: reactjs react-native expo


    【解决方案1】:

    尝试在你的 console.log() 中用 + 替换 ,

    【讨论】:

    • 但这不应该是一个问题,事实上我正在传递一个单独的参数,我一直这样做。
    猜你喜欢
    • 2018-08-20
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 2020-09-19
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多