zustandjs / zustand-slices

A slice utility for Zustand
MIT License
137 stars 6 forks source link

support async action well #11

Closed zhy0216 closed 2 months ago

zhy0216 commented 2 months ago

a small fix for async action type when manual typing

dai-shi commented 2 months ago

async action

I'm not sure what you mean by async action, but this async action is not supported for slice actions. It has to return (prev: Value) => Value.

However, withActions, it's supported.

Anyway, feedback is welcome and a reproduction or code snippet would help.

zhy0216 commented 2 months ago

async action

I'm not sure what you mean by async action, but this async action is not supported for slice actions. It has to return (prev: Value) => Value.

However, withActions, it's supported.

Anyway, feedback is welcome and a reproduction or code snippet would help.

get it. thx. what i am trying to do is to have inc & inc1 functions in the code snippet here: https://stackblitz.com/edit/vitejs-vite-qyrkei?file=src%2FApp.tsx Notice the type error on inc1 function. I think my code can support this situation.

dai-shi commented 2 months ago

Check this. As you see, inc1 button works unless inc is used. But once inc is clicked, inc1 no longer works. https://stackblitz.com/edit/vitejs-vite-gcckgg?file=src%2FApp.tsx

That's what I mean by it's not supported.

withActions has a different syntax, and can do async. However, I'm not sure if this is something most people expect: https://stackblitz.com/edit/vitejs-vite-7gfvvk?file=src%2FApp.tsx

zhy0216 commented 2 months ago

Check this. As you see, inc1 button works unless in is used. But once inc is clicked, inc1 no longer works. https://stackblitz.com/edit/vitejs-vite-gcckgg?file=src%2FApp.tsx

That's what I mean by it's not supported.

withActions has a different syntax, and can do async. However, I'm not sure if this is something most people expect: https://stackblitz.com/edit/vitejs-vite-7gfvvk?file=src%2FApp.tsx

get it! thanks