donavon/use-persisted-state

Is it possible to detect the origin tab of an update?

hcharley opened this issue · 1 comments

For example:

const useOpts = createPersistedState('key');

const Comp = props => {
  const [opts, setOpts] = useOpts({
    show: false
  });
  useEffect(() => {
    if (opts.show) {
      console.log('Show');
    } else {
      console.log('Hide');
    }
    if (opts._originDoc === document) {
      console.log('Origin was from this tab');
    } else {
      console.log('Origin of update was from another tab');
    }
  }, [opts.show])
  return (
    <>Test</>
  );
}

Yes, there is a way to find out if it came from this tab or another but we don't have the code to pass it back to you, maybe if you tell me your use-case we could change it.