如何在sendbird-uikit包的onChannelSelect道具中使用setState方法设置条件以设置频道网址?

问题描述

每当呈现组件时,都会调用

onChannelSelect 函数,从而重置 channelUrl 变量。因为当我们单击任何频道时,该频道网址不会更改。每次第一个频道的网址是从频道列表中设置的。那么我该如何使用setState方法设置频道网址?

import { ChannelList,SendBirdProvider,Channel } from "sendbird-uikit";

 setChannelUrl = (channel) => {
        console.log("channel",channel.url)
        this.setState({ channelUrl: channel.url })

    }
<div className="container cart">
                        <SendBirdProvider appId={global.chat.sendbirdAppId}
                            userId={profile.sendbird_id} >
                            <div className="card card-aspenku">
                                <div className="row">
                                    <div className="col-md-4" style={{ height: '400px' }} >
                                        <ChannelList
                                            onChannelSelect={(channel) => {
                                                if (this.state.channelUrl === "" || 
                                                    this.state.channelUrl !== channel.url) 
                                                {
                                                    console.log("channel")
                                                    this.setChannelUrl(channel)
                                                }
                                                else {
                                                    console.log("no channel")
                                                }
                                            }}
                                            queries={{
                                                channelListQuery: {
                                                    includeEmpty: true,},applicationUserListQuery: {
                                                    limit: 30,userIdsFilter: [profile.sendbird_id],}
                                            }}
                                        />
                                    </div>
                                    <div className="col-md-8" style={{ height: '400px' }}>
                                        {this.state.channelUrl && <Channel
                                            channelUrl={this.state.channelUrl}
                                            queries={{
                                                messageListParams: {
                                                    senderUserIds: [profile.sendbird_id],prevResultSize: 10,includeParentMessageText: true,includeReaction: true,}
                                            }}

                                        />}
                                    </div>
                                </div>
                            </div>
                        </SendBirdProvider>
                    </div>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)