ConrabOpto / mst-query

Query library for mobx-state-tree
MIT License
110 stars 7 forks source link

Support interval fetch #64

Open devtyty opened 6 months ago

devtyty commented 6 months ago

Can you add more interval fetch for query?

k-ode commented 6 months ago

I'd like to add this eventually, but in the meantime you can get the same thing with useEffect:

const { query } = useEffect(store.query);

useEffect(() => {
   const id = setInterval(() => {
       query.invalidate()
   }, 5000);
   return () => {
       clearInterval(id);
   }:
}, [query]);
devtyty commented 6 months ago

I'd like to add this eventually, but in the meantime you can get the same thing with useEffect:

const { query } = useEffect(store.query);

useEffect(() => {
   const id = setInterval(() => {
       query.invalidate()
   }, 5000);
   return () => {
       clearInterval(id);
   }:
}, [query]);

Yah! me too. But i think own lib should support for this to avoid boilerplate code