首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不变违规试图使帧超出范围索引NaN

不变违规试图使帧超出范围索引NaN
EN

Stack Overflow用户
提问于 2019-01-25 21:52:17
回答 1查看 1.9K关注 0票数 4

我正在从连培根运行一个连培根聊天应用程序示例,并遇到了frame out of range NaN错误:

以下是package.json:

代码语言:javascript
复制
 "firebase": "^5.8.0",
    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-native-elements": "^0.19.1",
    "react-native-gesture-handler": "^1.0.15",
    "react-native-gifted-chat": "^0.7.0",
    "react-navigation": "^3.0.9"

有一些关于不同情况下的错误的在线帖子。该错误指向GiftedChat中的Chat.js。我不知道是什么导致了这个错误。

代码语言:javascript
复制
import React, { Component} from 'react';
import {View, StyleSheet } from 'react-native';
import { GiftedChat } from 'react-native-gifted-chat';
import Fire from '../Fire';

class Chat extends React.Component {
    static navigationOptions = ({ navigation}) => ({
        title: (navigation.state.params || {}).name || 'Chat!',
    });

    state = {
        messages: {},
    };

    componentDidMount() {
        Fire.shared.on(message =>
              this.setState(previousState => ({
                messages: GiftedChat.append(previousState.messages, message),
              }))
        );
    }

    componentWillUnmount() {
      Fire.shared.off();
    }

    get user() {
      // return our name and our UID for GiftedChat to parse
      return {
          name: this.props.navigation.state.params.name,
          _id: Fire.shared.uid,
      };
    }

    render() {
        return (
            <GiftedChat   <<<<==this is line:37
              messages={this.state.messages}
              onSend={Fire.shared.send}
              user={this.user}
            /> 
        );
    }
}

const styles = StyleSheet.create({});



export default Chat;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-25 22:01:22

看起来错误处于消息的初始状态。

你已经把你的状态定义为

代码语言:javascript
复制
state = { 
  messages: {} 
}

消息应该定义为数组,因此将初始状态更新为

代码语言:javascript
复制
state = { 
  messages: []
}

从文件中

  • Messages (数组)-要显示的消息

https://github.com/FaridSafi/react-native-gifted-chat#props

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54373275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档