# \[React Native\] Disconnect error in v4

**URL:** <https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973>\
**Category:** JavaScript\
**Tags:** chatsdk, react-native\
**Created:** [June 29, 2022, 6:53am UTC](https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973 "2022-06-29T06:53:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jabir\_Muhammad](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/jabir_muhammad/32/2302_2.png) [@Jabir\_Muhammad](https://community.sendbird.com/u/Jabir_Muhammad)\
**Post date:** [June 29, 2022, 6:53am UTC](https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973/1 "2022-06-29T06:53:41Z")

</div>

I am using v4 JS SDK with React Native.

```auto
{
   "@sendbird/chat": "^4.0.3",
   "react-native": "0.68.2"
}

```

I am getting the following error while trying to call `sb.disconnect()`

```auto
[TypeError: window.removeEventListener is not a function. (In 'window.removeEventListener("visibilitychange", this._toggleState.bind(this), {
        capture: !0
      })', 'window.removeEventListener' is undefined)]

```

my code snippet

```auto
 const disconnectSendbird = useCallback(() => {
    if (sendbirdChannelRef.current) {
      console.log('sendbird:ChannelDisconnecting');
      sendbirdChannelRef.current
        .exit()
        .then(() => {
          console.log('sendbird:sendbirdChannelRefDisconnected');
          sendbirdChannelRef.current = null;
          if (sendbirdRef.current) {
            console.log('sendbird:Disconnecting');
            sendbirdRef.current
              .disconnect()
              .then(() => {
                console.log('sendbird:sendbirdRefDisconnected');
                sendbirdRef.current = null;
              })
              .catch(error => {
                console.log('sendbird:sendbirdDisconnectError', error);
              });
          }
        })
        .catch(error => {
          console.log('sendbird:sendbirdChannelExitError', error);
        });
    }
  }, []);

```

The WebSocket connection to sendbird is not closing, please help me with this error.

---

<div class="post-metadata">

**Author:** ![Jason](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/jason/32/488_2.png) [@Jason](https://community.sendbird.com/u/Jason)\
**Post date:** [June 30, 2022, 1:28am UTC](https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973/2 "2022-06-30T01:28:20Z")

</div>

@Jabir_Muhammad Hi there.

I will take a look. 🙂

---

<div class="post-metadata">

**Author:** ![Jason](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/jason/32/488_2.png) [@Jason](https://community.sendbird.com/u/Jason)\
**Post date:** [July 1, 2022, 6:48am UTC](https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973/3 "2022-07-01T06:48:41Z")

</div>

@Jabir_Muhammad Hi there.

Sendbird JS engineers looked at this issue and mention that there can be some side effect of using this. Are you using the below code?

```auto
window.addEventListener = function () {
  console.log("addEventListener");
};

```

The side effect is to cause an error thrown for

`await sendbird.disconnect()`

Our engineers will work to try to mitigate the side effect in a new release. I’ll get back with a timeline.

---

<div class="post-metadata">

**Author:** ![Jabir\_Muhammad](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/jabir_muhammad/32/2302_2.png) [@Jabir\_Muhammad](https://community.sendbird.com/u/Jabir_Muhammad)\
**Post date:** [July 1, 2022, 11:23am UTC](https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973/4 "2022-07-01T11:23:43Z")

</div>

@Jason No, i am not using the above mentioned code.

---

<div class="post-metadata">

**Author:** ![Jason](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/jason/32/488_2.png) [@Jason](https://community.sendbird.com/u/Jason)\
**Post date:** [July 4, 2022, 12:48am UTC](https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973/5 "2022-07-04T00:48:31Z")

</div>

@Jabir_Muhammad Hi again.

I heard from our engineers that they plan to release by Thursday 7th July, at the latest. I will keep an eye out for the update.

---

<div class="post-metadata">

**Author:** ![Jabir\_Muhammad](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/jabir_muhammad/32/2302_2.png) [@Jabir\_Muhammad](https://community.sendbird.com/u/Jabir_Muhammad)\
**Post date:** [July 7, 2022, 7:50am UTC](https://community.sendbird.com/t/react-native-disconnect-error-in-v4/4973/6 "2022-07-07T07:50:06Z")

</div>

@Jason Just tried the new `@sendbird/chat@4.0.5`, it does not connecting for me.  
Showing the same behavior as my old issue.

> [@\[React Native\] TypeError: undefined is not an object (evaluating 'Vn.of(this.\_iid).fetch')](https://community.sendbird.com/t/react-native-typeerror-undefined-is-not-an-object-evaluating-vn-of-this-iid-fetch/4895/8):
>
> @Jason I can confirm that this specific issue has been fixed. Thank you for the update.
