Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atoms are not visible in Redux Devtools if the atom value is not used #24

Open
tmatz opened this issue Jan 30, 2023 · 2 comments
Open

Comments

@tmatz
Copy link

tmatz commented Jan 30, 2023

I am using useAtomsDevtools().

If I use useSetAtom() for atom in the react component and do not useAtom() or useAtomValue(), the atom is not displayed in the Redux Devtools.

As a workaround, I was able to display the atom in Redux Devtools by using the store obtained with useStore() and setting store.sub(atom, () => {}).

  const store = useStore();
  useEffect(() => {
    if (process.env.NODE_ENV !== 'production') {
      return store.sub(myAtom, () => {
        // nop
      });
    }
    return undefined;
  }, [store]);

Although useAtomDevtools() will allow you to display with the Redux Devtools, we prefer not to use it because it causes unnecessary re-rendering.

It would be nice if useAtomsDevtools() would also display the atom when useSetAtomValue() is used.

@dai-shi
Copy link
Member

dai-shi commented Jan 30, 2023

This sounds very difficult.
If we simply display (add to the list) with useSetAtom, it will be infinite and leak memory. It might be fine in practice, but we pay attention for memory leaks and won't take such approach.

In v2 API, your workaround seems most reasonable for now. If you are using default store (no providers), getDefaultStore should help, and you don't need useEffect (and leaks memory).

@tmatz
Copy link
Author

tmatz commented Jan 31, 2023

@dai-shi
Thank you for your response!

Right now jotai-devtools is using useAtom(), which affects React rendering. I guess this will change to an implementation using the v2 store API.

Also, it would be nice to be able to connect jotai with redux devtools outside of React.

I would like to dig deeper into the source, as I still don't fully understand the possibility of an infinite loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants