【问题标题】:I am having video-course about creating Slack chat and now i have some problems我正在上有关创建 Slack 聊天的视频课程,现在我遇到了一些问题
【发布时间】:2019-04-01 16:21:41
【问题描述】:

我正在尝试从数据库(firebase)输出消息。 在控制台中一切正常,但是当它没有显示在组件中时。 看起来我的 Message 组件有一些问题,但是 idk...

https://github.com/Dronrom/app 这是代码

enter image description here

应该是这样的

【问题讨论】:

    标签: reactjs redux react-redux semantic-ui-react


    【解决方案1】:

    您好像忘记从 displayMessages 方法返回节点元素。

    这可能会对您有所帮助:

     displayMessages = messages => {
        // Check if message list is not empty
        if(messages.length > 0) {
            // Create new constant and collect it with messages
            const messagesList = messages.map(message => (
                <Message 
                    key={message.timestamp}
                    message={message}
                    user={this.state.user}
                />
            ))
    
            // Return React Nodes collection from method
            return messagesList;
        }
        // Return null when message list is empty
        return null;
    }
    

    顺便说一句,在从 firebase 获取数据时,您会进行许多不必要的重新渲染

    【讨论】:

    • 非常感谢)))即使我在它运作良好之前写了回报=)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    相关资源
    最近更新 更多