immerjs / use-immer

Use immer to drive state with a React hooks
MIT License
4.04k stars 92 forks source link

Can't get the types to work properly with `useImmerReducer` #19

Closed benoitgrelard closed 5 years ago

benoitgrelard commented 5 years ago

Hi there,

❤️ immer, and ❤️this little gem on top, making it even easier/more readable to use immer for my reducers.

However, when using useImmerReducer I cannot get the resulting state and dispatch to be typed correctly, I get any for both instead.

Here's a CodeSandbox showing the issue: https://codesandbox.io/s/p75vmyvo1j

You'll find a working example using immer's + React's useReducer and Reducer type as well as a version using useImmerReducer. They both technically work perfectly fine, it's just a typing issue. See the comments in the code for more explanation.

I know it's not a huge deal, but if I can help and improve this little 💎then that'd be awesome!

✌️

mweststrate commented 5 years ago

Thanks for reporting, the types were missing. Should be fixed in version 0.3.0