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

Unsubscribe withObservables when component unmount #138

Open
Coder231456 opened this issue Jul 7, 2023 · 1 comment
Open

Unsubscribe withObservables when component unmount #138

Coder231456 opened this issue Jul 7, 2023 · 1 comment

Comments

@Coder231456
Copy link

Is there any anyway to unsubscribe observable when component unmount.

i am getting below error, when component unmount

Warning: Internal React error: Attempted to capture a commit phase error inside a detached tree. This indicates a bug in React. Likely causes include deleting the same fiber more than once, committing an already-finished tree, or an inconsistent return pointer.

Error message:

TypeError: Cannot convert undefined or null to object
    in ChatComp (created by withObservables[item] { chatList })
    in withObservables[item] { chatList } (created by gestureHandlerRootHOC(withObservables[item]))
    in RNGestureHandlerRootView (created by GestureHandlerRootView)
    in GestureHandlerRootView (created by gestureHandlerRootHOC(withObservables[item]))
    in gestureHandlerRootHOC(withObservables[item]) (created by WrappedComponent)
    in WrappedComponent
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in Chat(RootComponent)

My code

 const getChatDispObserve = cid => {
    try {
        console.log('get data', cid);
        // const chatColl = database
        //   .get(CHAT_COLL)
        //   .query(Q.where('cid', cid), Q.experimentalSortBy('created_at', Q.desc));
        const chatColl = database
            .get(CHAT_COLL)
            .query(Q.where('cid', cid));
        const observable = chatColl.observeWithColumns(['sent_st']);

        return observable;
    } catch (e) {
        console.error('GetChatDispObserve', e);
    }
};

const enhance = withObservables(['item'], (props) => {
  const chatList = GetChatDispObserve(props.item.cid);
  return {
    chatList
  };
});
const EnChatComp = enhance(ChatComp);
@radex
Copy link
Collaborator

radex commented Jul 7, 2023

I think the issue is in the ChatComp component, not in the un subscription. Observables are unsubscribed on component unmount.

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

No branches or pull requests

2 participants