rocicorp / replicache-react

Miscellaneous utilities for using Replicache with React
MIT License
23 stars 8 forks source link

`useSubscribe` doesn't re-run if called with different args, even if they are in the dependencies #23

Closed aboodman closed 10 months ago

aboodman commented 2 years ago

This doesn't seem right:

function subConst(rep: Replicache<M>, val: string) {
  return useSubscribe(rep, (tx) => val, "", [val]);
}

var counter = 0;

function MyComponent({rep}: {rep: Replicache<M>}) {
  const val = ++counter % 2 === 0 ? "foo" : "bar";
  const sub = subConst(rep, val);
}

The subscription never gets re-evaluated when the value passed in changes.

aboodman commented 2 years ago

Looking at the code it seems like this should work (the deps from useSubscribe are passed into useEffect). Let me debug further.

arv commented 2 years ago

The subscription itself never fires because there are no get/has/scan. But the hook should unsubscribe and create a new subscription if the dependencies changes.