parse-react icon indicating copy to clipboard operation
parse-react copied to clipboard

useParseQuery subscription

Open hugobarragon opened this issue 3 years ago • 3 comments

I'd like to request a feature / bug useParseQuery works good in mount/unmout scnearios, but with react-navigation they dont have this lifecycles so it is impossible to use useParseQuery because it will keep requesting / updating other Screens, and I think with this will bring other level of customization, ex: click on somthing and being able to stop requesting live.

It could actually be a solution to use the enableLiveQuery to start/stop at any time Is it possible to change enableLiveQuery on options and will it start / stop

The main objective is something like this

import { useIsFocused } from '@react-navigation/native';
import React,{ useEffect} from 'react';
// ...

function App() {
  const isFocused = useIsFocused();
  const {results,liveQuerySubscription} = useParseQuery(query);

useEffect(()=>{
if(!isFocused ){
// stop requesting
 liveQuerySubscription.unsubscribe();
}

},[isFocused ])

  return <Text>{isFocused ? 'focused' : 'unfocused'}</Text>;
}

But exporting the liveQuerySubscription maybe would not be the greatest solution because when we return to the same srceen we, mount event will not be trigered and we want to start requesting again...

What you guys think would be the best solution?

hugobarragon avatar Dec 21 '21 16:12 hugobarragon

should this work to stop / start live requesting on demand?

  const isFocused = useIsFocused();
  const {results} = useParseQuery(query,{enableLiveQuery  :isFocused });

hugobarragon avatar Dec 21 '21 16:12 hugobarragon

When I navigate between two screens it gives me this error on the console. I'm using useParseQuery in both but for different requests.

https://user-images.githubusercontent.com/96492663/146973458-35fb7279-129f-4e43-b1d6-3674e0155c87.MOV

claudiarsl avatar Dec 21 '21 17:12 claudiarsl

@claudiarsl Unfortunately, I have exactly the same problem. Were you able to solve the error somehow?

JHuenerberg avatar Sep 02 '22 09:09 JHuenerberg