Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛] TypeError: Cannot read property 'state' of undefined #2777

Open
luannguyenhealthli opened this issue Nov 13, 2024 · 3 comments
Open

Comments

@luannguyenhealthli
Copy link

Issue

Describe your issue here
TypeError: Cannot read property 'state' of undefined

Steps to reproduce

Steps to reproduce the behavior:

  1. I'm using the "stream-chat-react-native" version "^5.41.1", and there’s no issue when getting the ChannelList.
<Chat client={chatClient}>
          <ChannelList
        filters={{
          joined: true,
          members: { $in: [userStream.userId] },
        }}
        additionalFlatListProps={{
          ListFooterComponent: FooterLoadMoreButton,
          onEndReached: () => null,
        }}
        onSelect={(channel) => {
          navigation.navigate("StreamChatDetail", {
            channel,
          });
        }}
        numberOfSkeletons={8}
        PreviewAvatar={({}) => <Fragment />}
        PreviewTitle={({ channel }) => (
          <Text
            style={{
              ...fonts.type.base(15, "#000000"),
              fontWeight: channel.countUnread() ? "600" : "400",
            }}
          >
            {channel.data?.name || channel.cid}
          </Text>
        )}
      />
     </ChannelList>
</Chat>
  1. But when I use it in the ThreadList, it throws an error like in the screenshot.

<Chat client={chatClient}> <ThreadList isFocused={isFocused} /> </Chat>
Simulator Screenshot - iPhong 14 Pro 18 0 - 2024-11-13 at 13 59 58

Expected behavior

The API and components is more stable or the error is more descriptive.
Additionally, please help me handle the null cases. I’ve encountered many instances and had to add the '?' symbol. This is quite frustrating.

@luannguyenhealthli
Copy link
Author

Screenshot 2024-11-13 at 14 18 50

@luannguyenhealthli
Copy link
Author

Screenshot 2024-11-13 at 14 23 34

@isekovanic
Copy link
Contributor

isekovanic commented Nov 13, 2024

Hi @luannguyenhealthli ,

It seems to me like you're passing an uninitialised client to the Chat component around the ThreadList. The ThreadManager encapsulated in client.threads is initialised whenever the client is initialised.

Can you confirm that client.threads exists ?

If it does not, are you by any chance installing the stream-chat library as well for some reason ? If that's the case you would also need to bump it to reflect the version used in version 5.41.1 of the React Native SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants