jotai-devtools
jotai-devtools copied to clipboard
Atoms are not visible in Redux Devtools if the atom value is not used
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.