use-persisted-state icon indicating copy to clipboard operation
use-persisted-state copied to clipboard

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

Open hcharley opened this issue 5 years ago • 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</>
  );
}

hcharley avatar Jun 29 '19 03:06 hcharley

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.

revelcw avatar Nov 09 '19 17:11 revelcw