mutativejs / use-mutative

A 2-6x faster alternative to useState with spread operation.
MIT License
63 stars 2 forks source link

Draft is not an `Draft<T>` #2

Closed chpio closed 6 months ago

chpio commented 1 year ago

Hi, the passed-in draft has the type T (but i would expect it to be Draft<T>), making the draft readonly if the original data type was defined as readonly.

unadlib commented 1 year ago

Hi, the passed-in draft has the type T (but i would expect it to be Draft<T>), making the draft readonly if the original data type was defined as readonly.

Could you provide an example? In fact, you can use draft: Draft<typeof initState>.

chpio commented 1 year ago

For example the same way you would in immer. By defining the fields in your state as immutable with readonly, but get mutable fields in the produce fn: https://immerjs.github.io/immer/typescript

This works just fine with mutative#create + react#useState, just not with use-mutative#useMutative

unadlib commented 6 months ago

hi @chpio , we have released version 1.0 and comprehensively fixed all known issues. Feel free to give use-mutative a try!