-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[devtools] doesn't log actions since v2 #77
Comments
Hey @pzi, As you can see on the line https://github.com/react-spring/zustand/blob/master/src/middleware.ts#L33, you need to put For example: const [useStore] = create(devtools(set => ({
count: 1,
inc: () => set(state => ({ count: state.count + 1 }), 'inc'),
dec: () => set(state => ({ count: state.count - 1 }), 'dec')
}))) I had the same problem too! Hope this help. |
thanks for the suggestion @VuHG, however, it seems that the types in typescript are not up-to-date as it's complaining about |
do you know what types it would need? im still struggling with TS. i can update and cut a release to fix this. |
Can you try this this @pzi: import create, { State, PartialState } from 'zustand'
import { devtools } from 'zustand/middleware'
type NamedSetState<T extends State> = (partial: PartialState<T>, name?: any) => void
interface Count {
count: number
}
const [useStore] = create<Count>(devtools((set: NamedSetState<Count>) => ({
count: 1,
inc: () => set((state: any) => ({ count: state.count + 1 }), 'inc'),
dec: () => set((state: any) => ({ count: state.count - 1 }), 'dec')
}))); @drcmda, should we export this in middleware.ts export type NamedSetState<T extends State> = (partial: PartialState<T>, name?: any) => void |
i guess, or should it fallback to some default name = "action" or something? would you make the PR? |
Hey drcmda, i'm struggling with TS too 😅 . This is popular library (can affect a lot of devs) so i think it better to wait for some TS expert helping us here. |
Yeah with the type override it works :) Will use that for now. thanks |
I was considering submitting a PR to change the following line:
in https://github.com/react-spring/zustand/blob/master/src/middleware.ts#L33 to
but that would mean it would always log for to devtools for everyone. Unsure if that's desired? It actually would also make more sense to remove the type from |
@JeremyRH what do you think? |
@pzi Your issue const store: StateCreator<DefaultState> The type DevToolsStateSetter<T> = (partial: PartialState<T>, name?: string) => void
const store = (
set: DevToolsStateSetter<DefaultState>,
get: GetState<DefaultState>
): DefaultState => ({
...DefaultStoreState,
...
}) We should export a |
For anyone who comes here looking for a quick fix, my solution was to make a type based on the normal StateCreator: import { State, SetState, StateCreator } from 'zustand';
/** To allow named functions when using devtools */
type StateCreatorDev<T extends State> = (
set: (partial: Parameters<SetState<T>>[0], name?: string) => void,
get: Parameters<StateCreator<T>>[1],
api: Parameters<StateCreator<T>>[2]
) => T; (edited to work properly, my test wasn't correct) |
Can we get this in the docs? |
I followed the naming suggestions in this thread, but was still not seeing actions. |
Does anybody know what's the status of this issue? |
Hey @dai-shi, @VuHG Solution works. But however, if we use immer we have to pass args like below otherwise it will not show state updates in the dev tools. const immer = (config) => (set, get, api) =>
config((fn, args) => {
// args equals to the name we passed to the function in our store ("SET_CART_OPEN", "SET_BACKDROP_OPEN")
return set(produce(fn), args), get, api;
});
const [useStore] = create<Store>(
devtools(
immer((set) => ({
cart: {
open: false,
setOpen: (value) =>
set((state) => {
if (typeof value !== "undefined") {
state.cart.open = value;
} else {
state.cart.open = !state.cart.open;
}
}, "SET_CART_OPEN"),
},
backdrop: {
open: false,
setBackdropOpen: (value) => {
set((state) => {
state.backdrop.open = value;
}, "SET_BACKDROP_OPEN");
},
},
}))
)
); |
@sanojsilva Thanks for the note. Let me read the thread again. So, the issue can be divided into three pieces, correct?
BTW, I have some questions about typing with immer. #96 |
v3 has |
Now v3 is out, We need to fix this. Does anyone have ideas? |
Very helpful issue thread! Saved me some hours |
I think I fixed it fully. #167 |
When updating from 1.0.7 to 2.2.1, I lose the tracking of all actions in the Redux devtools:
2.2.1
1.0.7
The app works just fine and the store updates correctly when using the app, it just doesn't log out the commits any more.
Using it like:
Any pointers would be appreciated. Let me know if you need more detail and I will update this post.
Cheers & thanks
Patrik
The text was updated successfully, but these errors were encountered: